[hack] show all items in single calendar

Help with installation and general calendar setttings

[hack] show all items in single calendar

Postby Cypriano » Wed May 04, 2011 8:54 pm

Hello, very nice script!
Recently I have searched for something like this, and finally here it is :D
Thank you!

I needed to show rooms reservations, so I changed the script a bit, and now all the rooms can be shown in a single calendar.

Here is a screenshot (the mod is only for front-end viewing, not for admin section):
Image

Below you can find my Hack, to the script. It is not fully tested yet, but it works quite well. Use it for your own responsibility.

How to use it
- First possibility - additional option in dropdown (modify the default index.php, line 40, add the line with value="0"):
Code: Select all
<select name="id_item" class="select" onchange="this.form.submit();">
               <option value="0">Show All</option> '.sel_list_items($_REQUEST["id_item"]).'
            </select>


- Second possibility - always show all entries, without dropdown. Remove the select lines in index.php lines 39-41, and modify the line 20:
Code: Select all
var id_item = 0;


Now the hacking

1. In ac-includes/ajax/calendar.ajax.php, at the bottom:
Code: Select all
// create the calendar
if ($id_item ==0 )
  echo draw_mycal($id_item,$the_month,$the_year);
else
  echo draw_cal($id_item,$the_month,$the_year);


2. In ac-content/themes/default/css/avail-calendar.css, at the bottom add:
Code: Select all
   /* all items addition */
   
.allitems .cal_month {
  width: 525px;   
  }
.allitems .cal_month ul{
  width: 525px;
}
.allitems .cal_month ul li {
  width:12px;
}
.allitems .cal_month ul li.item_name {
  width:50px;
}


3. The most important part, new function draw_mycal(), which is adapted original draw_cal() function. Just add the code to ac-includes/functions.inc.php:
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;
}
Cypriano
 
Posts: 1
Joined: Wed May 04, 2011 8:21 pm

Re: [hack] show all items in single calendar

Postby chris » Thu May 05, 2011 5:08 pm

Hi,
Thanks for sharing this code with everybody. It looks pretty good and is well explained :)

I do actually also have a version for setting the calendar up like this and it is not dissimilar to yours though I have not published it on the forum.

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 joed89 » Thu May 12, 2011 7:06 am

Thank you for sharing this and it looks really nice. I will try it on my calendar and see how it goes. I need to have this implemented as I need to see multiple objects in the calendar. As I have different objects which can be reserved in a month. It would not make sense if I would make a calendar for each so this one would really help.
joed89
 
Posts: 5
Joined: Wed May 11, 2011 1:02 pm

Re: [hack] show all items in single calendar

Postby robertosalemi » Tue May 24, 2011 4:04 pm

Hello Cipriano,
your guide is really good, I also would like to have a list of all apartments in a single calendar, but unfortunately following your guide I did not succeed. Watch as you see the calendar:
Link: http://www.allevamenticinofilitaliani.c ... ndex_2.php

Can you help me?

Thanks.
robertosalemi
 
Posts: 9
Joined: Mon May 23, 2011 11:39 pm

Re: [hack] show all items in single calendar

Postby pauluk » Tue Jun 14, 2011 7:48 am

Firstly, thanks for the original software - a lot of time and effort must have gone into it and it's much appreciated.

However, I DO need to display several items on the one calendar so was interested in this MOD.

Unfortunately, I cant seem to get it to work.

I get the following two errors;

Call to undefined function sel_list_items()............./calendar/index.php on line 40


and in my admin panel

Call to undefined function list_numbers()............/calendar/ac-admin/config.admin.php on line 56


Any ideas please?

On the post made by Cypriano, he states "first possibility" and "second possibility" - Im guessing that is just a translation thing and not an instruction to do one or the other?

HELP (please) !!

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

Re: [hack] show all items in single calendar

Postby chris » Tue Jun 14, 2011 8:40 am

Hi,
Those 2 functions are defined within the ac-includes/functions.inc.php file.
With the modifications that you have made, make sure that you haven't deleted them by mistake.

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 9:28 pm

screenshot.jpg
screenshot.jpg (97.93 KiB) Viewed 10490 times


OK - I uploaded a fresh version of the availability calendar software and then followed the step-by-step instructions for the MOD.

Unfortunately, none of my calendar lines up - see the attached screenshot.jpg

Any ideas please?

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

Re: [hack] show all items in single calendar

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

I'm afraid that I can't do much with an image.
Can you share an url so I can take a look at the css?

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 9:46 pm

The website isnt live yet and is a bit hush hush.

here it is [url removed by request] (i hope I can edit it out after ;) as cant have too many prying eyes just yet)

Cheers
Paul

Edit - url removed by Chris
pauluk
 
Posts: 6
Joined: Tue Jun 14, 2011 7:41 am

Re: [hack] show all items in single calendar

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

I can't find the calendar anywhere on that url (that I have now removed)
Could you send me a pm with the direct url to the calendar?

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

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron