[hack] show all items in single calendar

Help with installation and general calendar setttings

Re: [hack] show all items in single calendar

Postby chris » Thu Jun 16, 2011 9:55 pm

OK, no worries, I worked it out :) - I was expecting to see it within your design but realized that it wasn't yet.

I'll take a closer look at what is happening though my first impression is that either you haven't modified the css or that it is loading the wrong one.

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

Re: [hack] show all items in single calendar

Postby chris » Thu Jun 16, 2011 10:02 pm

It doesn't look like any changes have been made in the css file to adapt it to this new layout.

Here is a very quick revised version (done via Firebug) that should set you on your way (will probably need some tweaking):
Code: Select all
.cal_month ul li.booked_am, .cal_month ul li.booked_pm, .cal_month ul li.booked_pr_am, .cal_month ul li.booked_pr_pm {
    background-image: url("/calendar/ac-contents/themes/default/images/bg_days.png");
}
#cal_wrapper {
    color: #444444;
    font: 11px/1.6 Arial,sans-serif;
    margin: 20px auto;
    width: 1000px;
}
#the_months {
    float: left;
    width: 860px;
}
.clear {
    clear: both;
}
#ajax_message {
    background: none repeat scroll 0 0 #FFFFEE;
    border-bottom: 1px solid #CCCCCC;
    border-top: 1px solid #CCCCCC;
    float: left;
    margin-left: 10px;
    text-align: center;
    width: 260px;
}
.img_loading_month {
    margin: 50px;
}
#key_wrapper {
    float: right;
    text-align: center;
}
#key {
    background: none repeat scroll 0 0 #EEEEEE;
    color: #111111;
    width: 122px;
}
#key .cal_title {
    color: #FFFFFF;
}
#key ul {
    text-align: left;
}
#key ul li {
    float: none;
}
#key ul li span {
    display: block;
    margin-left: 22px;
    text-align: left;
    width: 90px;
}
#key #footer_data {
    clear: both;
    font-size: 0.7em;
}
#cal_controls {
    margin-bottom: 10px;
}
#cal_controls #cal_prev {
    float: left;
}
#cal_controls #cal_next {
    float: left;
    margin-left: 2px;
}
#cal_controls #cal_admin {
    float: left;
    margin-left: 10px;
}
.cal_month {
    background: none repeat scroll 0 0 #FFFFEE;
    border: 1px solid #006699;
    border-radius: 6px 6px 6px 6px;
    color: #666666;
    float: left;
    line-height: 20px;
    margin-bottom: 6px;
    margin-right: 6px;
    min-height: 194px;
    padding-bottom: 6px;
    width: 850px;
}
#key .cal_title, .cal_month .cal_title {
    background: none repeat scroll 0 0 #006699;
    border-bottom: 1px solid #CCCCCC;
    color: #FFFFFF;
    padding: 2px;
    text-align: center;
}
.cal_month ul {
    clear: both;
    color: #FFFFFF;
    list-style: none outside none;
    margin: auto;
    padding: 4px;
}
.cal_month ul li {
    background-color: #DDDDDD;
    border: 1px solid #CCCCCC;
    border-radius: 3px 3px 3px 3px;
    color: #000000;
    float: left;
    font-size: 90%;
    height: 20px;
    margin-bottom: 1px;
    margin-right: 1px;
    text-align: center;
    width: 20px;
}
.cal_month ul.cal_weekday li {
    background-color: #006699;
    border: 1px solid #006699;
    color: #FFFFFF;
}
.cal_month ul li.cal_empty {
    background-color: #EEEEEE;
    border: 1px solid #EEEEEE;
    color: #CCCCCC;
}
.cal_month ul li.booked {
    background-color: #FF0000;
}
.cal_month ul li.booked_pr {
    background-color: #FF9700;
}
.cal_month ul li.offer {
    background-color: lime;
}
.cal_month ul li.changeover {
    background-color: pink;
}
.cal_month ul li.booked_am {
    background-position: 200px top;
}
.cal_month ul li.booked_pm {
    background-position: 230px top;
}
.cal_month ul li.booked_pr_am {
    background-position: 140px top;
}
.cal_month ul li.booked_pr_pm {
    background-position: 170px top;
}
.cal_month ul li.weekend {
}
.cal_month ul li.today {
    border: 1px dotted #006699;
}
.tips {
    background: none repeat scroll 0 0 #000000;
    border: 2px solid #666666;
    border-radius: 3px 3px 3px 3px;
    color: #FFFFFF;
    padding: 6px;
}
.cal_month ul li.weeknum_spacer {
    background-color: #FFFFEE;
    border: medium none;
    width: 4px;
}
.cal_month ul li.weeknum {
    background-color: green;
    width: 4px;
}
.cal_month ul li.item_name {
    width: 120px;
    text-align: left;
}


Let me know ho it goes :)

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

Re: [hack] show all items in single calendar

Postby pauluk » Thu Jun 16, 2011 10:28 pm

Hi Chris

I had changed the CSS as per Step2 in the Mod guide above but it didnt work.

Thanks for your code - it seems to have done the trick.

Now I can see about tweaking things to get it into my website etc.

HUGE thanks

Paul
pauluk
 
Posts: 6
Joined: Tue Jun 14, 2011 7:41 am

Re: [hack] show all items in single calendar

Postby pauluk » Fri Jun 17, 2011 9:35 pm

Hello Chris

I now have a problem within the Bookings area of Admin.

The calendar is missing and I get;

Fatal error: Call to undefined function draw_cal() in DOMAIN/calendar/ac-includes/ajax/calendar.ajax.php on line 39


Paul
pauluk
 
Posts: 6
Joined: Tue Jun 14, 2011 7:41 am

Re: [hack] show all items in single calendar

Postby chris » Fri Jun 17, 2011 9:45 pm

Hi,
I really don't know what you have done to cause this error.
Have you renamed or removed the draw_cal() function in the ac-includes/functions.inc.php file?
If you have, a quick solution might be to just add it in again from the original files.

As I mentioned earlier I haven't been through or tested this MOD code so I really don't know what all the implications would be with the changes that are suggested.

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

Re: [hack] show all items in single calendar

Postby pauluk » Fri Jun 17, 2011 10:02 pm

Hi

The only changes I made were as per the Mod instructions and your kind help with the css.

I edited that php page as the mod suggested;

Code: Select all
/* script:   Show all items hack to Ajax availability calendar
original script author: Chris Bolson
hacked script author: Cypriano.pl
*/
// my calendar
function draw_mycal($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 month
   $day_counter_tot   =   0; #   count total number of days showin INCLUDING previous and next months - use to get 6th row of dates
   

   //   CREATE THE CALENDAR
   $list_day_titles = '<li class="item_name"   title="">Item</li>';
   //   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=0; $k<$days_in_this_month; $k++){
         //echo "<br>".$k;
         if($first_week_day==7)    $first_week_day = 0;
         $weekday = substr($lang["day_".$first_week_day.""],0,2);
         $list_day_titles.='<li title="'.$lang["day_".$first_week_day++.""].'"> '.$weekday.'</li>';
      }
   }
   
   
   //   get bookings for this month and item from database
   $booked_days=array();
   $sql = "
   SELECT
      t3.desc_".LANG." AS the_item ,
      t1.the_date,
      t2.class,
      t2.desc_".LANG." AS the_state
     
   FROM   
    ".T_BOOKINGS_ITEMS." AS t3 
    LEFT JOIN  ".T_BOOKINGS." AS t1    ON    t1.id_item=t3.id  AND MONTH(t1.the_date)=".$month."  AND YEAR(t1.the_date)=".$year."
    LEFT JOIN   ".T_BOOKING_STATES." AS t2 ON     t2.id=t1.id_state   
   ";
   //echo $sql;
   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_item"]][$row["the_date"]]=array("class"=>$row["class"],"state"=>$row["the_state"],"item"=>$row["the_item"]);
   }
   
   
   
   //   loop thorugh days (til max in month) to draw calendar
   
   $list_days=array();
   $items=0;
   foreach ($booked_days as $booked_days_item) {
   $the_item = reset($booked_days_item);
    $list_days[$items] .= '
        <li class="item_name"   title="">'.$the_item["item"].'</li>';
    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_item)){
           $day_classes.=" ".$booked_days_item[$date_db]["class"];
           $day_title_state=" - ".$booked_days_item[$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[$items] .= '
        <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[$items] .= '<li class="weeknum">'.$week_num.'</li>';
        }
        $last_week_num=$week_num;
     
    }
    $items++;
   }
   
   //   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>';

   foreach ($list_days as $list_days_single ) {
    $the_cal.='<ul>
      '.$list_days_single.'
      </ul> ';
  }
   $the_cal.='<div class="clear"></div>';
   return $the_cal;
}


There seems to be references to both draw_cal() and also draw_mycal() in the php scripts - could these be conflicts or is this just std stuff that should be there?

Sorry for sounding really thick - I am trying to pick this coding stuff up as I go along but there is a LOT to grasp.

Paul
pauluk
 
Posts: 6
Joined: Tue Jun 14, 2011 7:41 am

Re: [hack] show all items in single calendar

Postby chris » Fri Jun 17, 2011 10:16 pm

The "draw_mycal()" function is not part of the original script.
Unless you modify the admin php code, it *requires* the original draw_cal() function to be able to create the calender.
So, without getting overly complicated with this, I suggest that you copy the draw_cal() function from the original code and put it into the functions file along with this modified and renamed function which I presume is what is being used to create the horizontal calendar.

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

Re: [hack] show all items in single calendar

Postby calnewb » Mon Jun 20, 2011 8:59 pm

Appreciate the OP and Chris for helping with this.

I was able to get the calendar to display multiple items on a single calendar using the OP's directions and the css from Chris; I have not been able to figure out how to get the days of the week to repeat beyond showing the first week. Please see screenshot.

Thanks in advance for your help.
Attachments
calendar2.jpg
Non-repeating week labels
calendar2.jpg (28.03 KiB) Viewed 4287 times
calnewb
 
Posts: 4
Joined: Mon Jun 20, 2011 8:48 pm

Re: [hack] show all items in single calendar

Postby chris » Mon Jun 20, 2011 9:30 pm

Hmm, if you have copied the mod code as posted at the beginning of this thread I don't see how that can have happened.
In the code you should have a loop that looks like this:
Code: Select all
for($k=0; $k<$days_in_this_month; $k++){
         //echo "<br>".$k;
         if($first_week_day==7)    $first_week_day = 0;
         $weekday = substr($lang["day_".$first_week_day.""],0,2);
         $list_day_titles.='<li title="'.$lang["day_".$first_week_day++.""].'"> '.$weekday.'</li>';
      }

If you haven't got that, how did you implement the changes?

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

Re: [hack] show all items in single calendar

Postby calnewb » Mon Jun 20, 2011 10:11 pm

Hi Chris,

I do have that same code listed. I think maybe it's how I added the OP's code for the functions.inc.php. I added their code to the original functions.inc.php file at line just before the ending ?>
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
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_item=".$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"];
}
    /* script:   Show all items hack to Ajax availability calendar
    original script author: Chris Bolson
    hacked script author: Cypriano.pl
    */
    // my calendar
    function draw_mycal($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 month
       $day_counter_tot   =   0; #   count total number of days showin INCLUDING previous and next months - use to get 6th row of dates
       

       //   CREATE THE CALENDAR
       $list_day_titles = '<li class="item_name"   title="">Item</li>';
       //   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=0; $k<$days_in_this_month; $k++){
             //echo "<br>".$k;
             if($first_week_day==7)    $first_week_day = 0;
             $weekday = substr($lang["day_".$first_week_day.""],0,2);
             $list_day_titles.='<li title="'.$lang["day_".$first_week_day++.""].'"> '.$weekday.'</li>';
          }
       }
       
       
       //   get bookings for this month and item from database
       $booked_days=array();
       $sql = "
       SELECT
          t3.desc_".LANG." AS the_item ,
          t1.the_date,
          t2.class,
          t2.desc_".LANG." AS the_state
         
       FROM   
        ".T_BOOKINGS_ITEMS." AS t3
        LEFT JOIN  ".T_BOOKINGS." AS t1    ON    t1.id_item=t3.id  AND MONTH(t1.the_date)=".$month."  AND YEAR(t1.the_date)=".$year."
        LEFT JOIN   ".T_BOOKING_STATES." AS t2 ON     t2.id=t1.id_state   
       ";
       //echo $sql;
       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_item"]][$row["the_date"]]=array("class"=>$row["class"],"state"=>$row["the_state"],"item"=>$row["the_item"]);
       }
       
       
       
       //   loop thorugh days (til max in month) to draw calendar
       
       $list_days=array();
       $items=0;
       foreach ($booked_days as $booked_days_item) {
       $the_item = reset($booked_days_item);
        $list_days[$items] .= '
            <li class="item_name"   title="">'.$the_item["item"].'</li>';
        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_item)){
               $day_classes.=" ".$booked_days_item[$date_db]["class"];
               $day_title_state=" - ".$booked_days_item[$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[$items] .= '
            <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[$items] .= '<li class="weeknum">'.$week_num.'</li>';
            }
            $last_week_num=$week_num;
         
        }
        $items++;
       }
       
       //   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>';

       foreach ($list_days as $list_days_single ) {
        $the_cal.='<ul>
          '.$list_days_single.'
          </ul> ';
      }
       $the_cal.='<div class="clear"></div>';
       return $the_cal;
    }
?>
calnewb
 
Posts: 4
Joined: Mon Jun 20, 2011 8:48 pm

PreviousNext

Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron