Calendar tweaking

Calendar tweaking

Postby aquado » Wed Apr 16, 2008 12:50 pm

Hello Chris,

I was looking through the forum and it let me learn how helpful your calendar can be :)
I'd like to make few changes in the callendar but I don't know where to start and it looks like I'll need your help.
I know where to change (in the code) "state" status that is written to the db for "special_state" (am/pm), but for state "booked" there is no entry in the db. Where should I add some line to make "state" - "booked" apear in the db?

Moreover I wanted to add one more icon at the beginning of each week with the week number and make it possible to change availability for entire week after clicking on that single, new icon/image.
And I'd like to disable ability to change state of the day for previous dates.

Can you show me how to do that or at least point me in the right direction?
Sorry that I have begunn a new topic - should have posted it with my previous question :oops:

Thank you,
Aquado.
aquado
 
Posts: 11
Joined: Wed Apr 09, 2008 4:27 pm

Re: Calendar tweaking

Postby chris » Wed Apr 16, 2008 9:24 pm

that's quite a few requests ;)

The way the calendar works is that, if it is in the database table and doesn't have a state (am or pm) it means that it is booked all day.

Preventing past days from being modified:
in the "inclues/functions.in.php" file find these lines:
Code: Select all
$date_alt       =    $lang["modify_availability_for"].' '.$lang["days"][$week_day].' '. $date_format;
$day_link_start   =   '<a href="#" onclick="ajax_mod_state(\''.$id.'\',\''.$this_date.'\',\''.$day_counter.'\',event); return false"  title="'.$date_alt.'" class="cal_day">';
$day_link_end   =   '</a>';

and replace with these:
Code: Select all
//check date is note BEFORE current
            $tmp_date      =   explode("-",$this_date);
            $date_timestamp =   mktime(0,0,0, $tmp_date[1], $tmp_date[2], $tmp_date[0]);
            $today_timestamp=   mktime(0,0,0,date('m'),date('d'),date('Y'));

            if( $date_timestamp>=$today_timestamp){
               //   modifiable dates FROM today (ie not before)
               $date_alt       =    $lang["modify_availability_for"].' '.$lang["days"][$week_day].' '. $date_format;
               $day_link_start   =   '<a href="#" onclick="ajax_mod_state(\''.$id.'\',\''.$this_date.'\',\''.$day_counter.'\',event); return false"  title="'.$date_alt.'" class="cal_day">';
               $day_link_end   =   '</a>';
            }

You will see there that we have converted the 2 dates (cal date and today) to timestamps to make a comparison, if the cal date is less than todays we do not show the link.

Adding week numbers and especially being able to update whole weeks is actually going to invlove quite a lot more work as it means creating a new javascript function and modifying the ajax.php file to accomodate the whole week bookings.
Unfortunately I am quite busy "working" at the moment so, although I hate to have to say it, I'm afraid that I can't do this one for you right now - sorry :(
It is however something that I think would be an interesting development for the script so I will bear it in mind for future versions.

Sorry to not be able to help more right now.

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

Re: Calendar tweaking

Postby aquado » Thu Apr 17, 2008 9:15 pm

Hi Chris,

thank you VERY MUCH for your help.
I'll wait for the next version of your calendar.

Aquado.
aquado
 
Posts: 11
Joined: Wed Apr 09, 2008 4:27 pm

Re: Calendar tweaking

Postby aquado » Fri Apr 18, 2008 12:50 pm

Hello Chris,

I saw on one of your posts that there were numbers in front of each week. Can you show me how to do that, please :?: I ask you because it wasn't explained.

Best wishes,
Aquado
aquado
 
Posts: 11
Joined: Wed Apr 09, 2008 4:27 pm

Re: Calendar tweaking

Postby chris » Fri Apr 18, 2008 1:19 pm

I think that you where the only one who requested that - I don't remember any other requests for it.

It is, however interesting and, after receiving your request I have actually started work on it but it is actually rather more complicated than I hoped so, as of yet, I haven't got a working version to be able to post here.

I will let you know as soon as I have something.

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

Re: Calendar tweaking

Postby chris » Wed Apr 23, 2008 1:30 pm

OK, I think I have this now, bear with me as I describe the steps necesarry...

1. CREATE NEW FUNCTION
in the functions.inc.php file add this new function:
Code: Select all
function get_week_number($timestamp) {
   $d = getdate($timestamp);
   $days = iso_week_days($d["yday"], $d["wday"]);
   if ($days < 0) {
      $d["yday"] += 365 + is_leap_year(--$d["year"]);
      $days = iso_week_days($d["yday"], $d["wday"]);
   } else {
      $d["yday"] -= 365 + is_leap_year($d["year"]);
      $d2 = iso_week_days($d["yday"], $d["wday"]);
      if (0 <= $d2) {
         /* $d["year"]++; */
         $days = $d2;
      }
   }
   return (int)($days / 7) + 1;
}

2. ADD EMPTY CELL TO TITLE ROW
At the beginning of the dra_cal() function, just after the <tbody> is opened, add this to the first row (ie BEFORE we write the week day titles):
Code: Select all
<td>&nbsp;</td>

it should look like this:
Code: Select all
<tbody>
      <tr>
         <td>&nbsp;</td>

3.ADD FIRST ROW WEEK NUMBER
After the title columns (ie the bit where it writes "M","T","W" etc....
add this to the first date row:
Code: Select all
<td>'.get_week_number(mktime(0,0,0,  $month,1, $year)).'</td>

This will calclulate the number for the first week basing it on the fact that the month always starts with the number 1 ;)

4. ADD WEEK NUMBER TO OTHER ROWS
We will now use the code that adds a new row every 7 days to add the week numbers as well.
Find this code: (bear in mind that you might have modified this for one of your other requests but I will use the "original" version for any others who might come across this thread and request the same feature):
Code: Select all
if($week_day == 0){
            $the_cal .= "</tr><tr>";
            ++$cal_row_counter;
         }

and replace with this:
Code: Select all
if( ($week_day == 0) && ($day_counter<$days_in_this_month )){
            if(CAL_START_DAY=="sun")   $date_timestamp =   mktime(0,0,0, $month,$day_counter,$year);
            else                  $date_timestamp =   mktime(0,0,0, $month,($day_counter+1),$year);
            $the_cal .= '
            </tr>
            <tr>
               <td>'.get_week_number($date_timestamp).'</td>
            ';
            ++$cal_row_counter;
         }


Well, that "should" be it, I realise that your version is slightly diferrant as we have been adding different mods, but hopefully you will now be "used" to the code and be able to add it now problems :)

Let me know how it goes :)

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

Re: Calendar tweaking

Postby aquado » Wed Apr 23, 2008 10:34 pm

YOU ARE GREAT :!: :!: :!:

I've just implemented all your tweaks and EVERYTHING works perfectly!!

Thank you so much...
Aquado.
aquado
 
Posts: 11
Joined: Wed Apr 09, 2008 4:27 pm

Re: Calendar tweaking

Postby kasafacil » Wed Jun 03, 2015 8:30 pm

Hola Chris como estas ?, hace mucho tiempo que no entraba en el foro, precisamente andaba buscando la manera de bloquear la semana completa y he dado con este post pero a pesar que aquado dice que funciona perfectamente, yo no acabo de saber donde colocar la llamada a la funcion que se añade nueva, podrias aclararmelo un poco ?, he colocado y cambiado todo tal y como lo dices pero esta funcion <td>'.get_week_number(mktime(0,0,0, $month,1, $year)).'</td>
no se donde ponerla o como ponerla.
el calendario esta incluido en mi web , es la version 2 y funciona bien, solo quiero poder seleccionar por semanas al igual que lo hago por noches.
gracias y un saludo
Miguel (kasafacil)
kasafacil
 
Posts: 12
Joined: Tue May 13, 2008 7:12 pm


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron