Disabling update but keeping date selection

Disabling update but keeping date selection

Postby davemarsh » Wed Jan 07, 2009 2:30 am

Hi Chris,

Great script. I've been playing with it for a couple of weeks and have almost integrated into a website I'm developing to take booking for three hotels that I run.

I'm learning a lot of this as I go and I've just about got it to stage where I can put it live (actually it is live but no-one knows it's there). The final obstacle I can't quite resolve is that I want to use the calendar to allow the user to choose an available date but not update the availabilty.

I can easily break the script to stop it changing the state but this is no good as I need the back end to function properly so my staff can keep update of availability in edit mode.

I'm aware of how to change the calendar between edit mode and public mode using $booked_days,1/0 but is there a way that when in public mode I can lock out the avaialability update but retain the 'clickability' of the calendar to allow for date selection?

It would be perfect if the user couldn't select a day that was booked out, only able to click on available days...

You can view the booking page of the site here: http://www.ifieldhotels.com/bookings.html (very much a work in progress).

Can you help me to solve this?

Many thanks and great work,
Dave
davemarsh
 
Posts: 11
Joined: Wed Jan 07, 2009 2:08 am

Re: Disabling update but keeping date selection

Postby chris » Wed Jan 07, 2009 12:14 pm

Hi there and welcome to the forum :)
Thanks for the comments about this script - I am glad that you like it and that, hopefully, it will be of use to you.

From what I understand you want to be able to allow your users to click on available dates (ie booked dates would not be clickable - is that right?) and, on doing so, in some way select them - ie the user would not be able to actually book that date.


To do this you would need to leave the state that you mentioned in the function to 1 (on).

Secondly you would need to be able to "identify" if the user is an admin or a normal web user looking for available dates.
This could be done in several ways, but really depends on what you have in place to detect you admin users. Are you using php sessions?
BAsically the idea is that, within the draw_cal() function, you are going to need to be able to detect the type of user to show one type of link or the other.
This is the block of code that you need to modify and "condition" (starts at line 71 more or less):
Code: Select all
   //   show ajax link or not
        if($show_link==1){
      $day_link_start   ='<a href="javascript:void;" onclick="ajax_mod_state(\''.$id.'\',\''.$this_date.'\',\''.$day_counter.'\',event);" title="Modificar disponibilidad para '.$lang["day_".$week_day.""].' '. $date_format.'" class="cal_day">';
      $day_link_end   ='</a>';
   }else{
      $day_link_start   ="";
      $day_link_end   ="";
   }

So, assuming that you have something like $_SESSION["admin_id"] (ie you are using a session variable to identify the admin user), you would do something like this:
Code: Select all
if(isset($_SESSION["admin_id"])){
  // admin user
  // show ink on all days
  $day_link_start='<a href="javascript:void;" onclick="ajax_mod_state(\''.$id.'\',\''.$this_date.'\',\''.$day_counter.'\',event);" title="'.$lang["day_".$week_day.""].' '. $date_format.'" class="cal_day">';
  $day_link_end   ='</a>';
}else{
  if(array_key_exists($this_date,$booked_days)){
    //   day booked  - NO LINK
    $day_link_start   ="";
    $day_link_end   ="";
  }else{
    //   available - show NEW LINK
    $day_link_start='<a href="javascript:void;" onclick="select_date(\''.$this_date.'\');" title="'.$lang["day_".$week_day.""].' '. $date_format.'" class="cal_day">';
    $day_link_end='</a>';
  }
}


So, hopefully you will see from that code that now we are actually not using the "link_state" (ie the "1" at the end of the function paramaters) as ALL the dates could be linkable.
The admin user has the same possibilities as before.
The web user now has the possibility to click on the available dates.
You will see that the web user date link now has a new action that calls a javascript function that I have called "select_date(the_date)" and, as you can see, would pass the selected date to this new function.
I have not gone as far as writing this javascript function for you. Firstly because I am not sure exactly what you want to do with the dates and secondly as you may well be able to do the javascript bit yourself ;)

Well, I hope that this at least points you in the right direction as to how to solve your problems ;)

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

Re: Disabling update but keeping date selection

Postby davemarsh » Wed Jan 07, 2009 6:23 pm

Hi Chris,

Thanks for the quick responce - this is exactly what I mean.

I was able to get the session code in with no problems and this works a treat. However I'm stuggling to work out the javascript function.

Previously I have been using the 'the_date' variable to pass the date through to a booking form. The user selected the date they wanted and clicked through to a booking form displaying their this date, they then add a few personal details and submit their complete booking.

My newbie approach was to write the code below to reformat the 'the_date' string to be more user friendly - ie to change 2009-01-01 into 01 January 2009 - and then pass it to the booking form via a submit button. I'd like the new 'select_date' function to do much the same (although bypassing the need for a submit button) but I've been staring at this all day and can't get anything to work :-)

Code: Select all
var selDate=new Array();
selDate['00']="Void";
selDate['01']="January";
selDate['02']="February";
selDate['03']="March";
selDate['04']="April";
selDate['05']="May";
selDate['06']="June";
selDate['07']="July";
selDate['08']="August";
selDate['09']="September";
selDate['10']="October";
selDate['11']="November";
selDate['12']="December";

document.getElementById('chosendate').value=(the_date.slice(8,10)+' '+selDate[the_date.slice(5,7)]+' '+the_date.slice(0,4));


Any help you can give me to get this working would be much appreciated.

Many thanks,
Dave
davemarsh
 
Posts: 11
Joined: Wed Jan 07, 2009 2:08 am

Re: Disabling update but keeping date selection

Postby chris » Wed Jan 07, 2009 6:38 pm

Hi again.
From your link I see that right now you have it linking to bookingform.php
Do you need to send any other data to that page or is it just the date?
If you are just sending the date I would forget about javascript and just send it as a normal url like this: booking.php?date='.$this_date.'

From what you are saying and what I can see from your url, you are not actually using the date that the user selects for anything other than posting it in your form (ie you are not saving it to the database or anything that requires it to be formatted) therefore you could either use php to format it before you add it to the link (ie in the calendar function or within your bookingform.php page so as to be able to display it "correctly" for your user.

Personally I would send it in the url as is, ie (eg) 2009-01-07 as otherwise the urlencoding might mess it up and also this way it is correctly formatted for inserting into a database "date" column if needed in the future.
Then, in your bookingform.php format it as required something like this (not tested):
Code: Select all
$months=array("","January","February","March","April"...);
$date_bits=explode($_REQUEST["date"]);
$date_display=$date_bits[2].' '.$months[$date_bits[1]].' '.$date_bits[0];

echo $date_display;



However, if you really want/need to use javascript to get and post the date, let me know and I will take a look ;)

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

Re: Disabling update but keeping date selection

Postby chris » Wed Jan 07, 2009 6:53 pm

just looking at you page again and see why you wanted to use javascript.... you where showing the date by the "submit" button...
To do this you could use your function that you had before to update the date by the button but modify the onclick to send the formated date rather than the numeric date.
Just use that function in my previous post within the draw_cal() function (the bit conditioned for the public user)

so you would have something like:
<a href="javascript:void;" onclick="select_date(\''.$date_display.'\');">

[EDIT]... actually it is even simpler.... we already have the month name defined within the function so you would do this:

Code: Select all
if(array_key_exists($this_date,$booked_days)){
  //   day booked  - NO LINK
  $day_link_start="";
  $day_link_end   ="";
}else{
  //   available - show NEW LINK
  $day_link_start='<a href="javascript:void;" onclick="select_date(\''.$week_day.' '.$month_name.' '.$year.'\');" title="'.$lang["day_".$week_day.""].' '. $date_format.'" class="cal_day">';
  $day_link_end   ='</a>';
}


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

Re: Disabling update but keeping date selection

Postby chris » Wed Jan 07, 2009 7:14 pm

$date_bits=explode($_REQUEST["date"]);

Sorry, that should have been:
Code: Select all
$date_bits=explode("-",$_REQUEST["date"]);


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

Re: Disabling update but keeping date selection

Postby davemarsh » Wed Jan 07, 2009 8:07 pm

Yep, spotted that one :-)

The bit that's not working now is this:

.$months[$date_bits[1]].

Doesn't show anything. Any ideas?

This approach is perfect for what I need at this stage. I intend to expand on the functionality of the system as I learn more about what I am doing but once this is working I have enough to put the site out there and start taking bookings.

Cheers,
Dave
davemarsh
 
Posts: 11
Joined: Wed Jan 07, 2009 2:08 am

Re: Disabling update but keeping date selection

Postby davemarsh » Wed Jan 07, 2009 8:18 pm

Ok, got it.

I just needed to change the array to this:

Code: Select all
$months=array("01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December");


Works a treat :-)

Thanks for all your help.

Dave
davemarsh
 
Posts: 11
Joined: Wed Jan 07, 2009 2:08 am

Re: Disabling update but keeping date selection

Postby chris » Wed Jan 07, 2009 9:14 pm

OK, good news :)

Site looks pretty good by the way.
Just one SEO tip - try to give each page a different title otherwise google and the other search engines may think that they are all the same page. It is also helpfull for you visitors.

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

Re: Disabling update but keeping date selection

Postby davemarsh » Wed Jan 07, 2009 9:49 pm

Yeah, i'll sort all that by the time I get the site finished.

One final question before I leave you in peace...

I've started a PHP Session on a password protected page and included calendar.php. It half works as the unavailable dates become clickable again, however nothing changes when you click a date.

Was this how you intended me to do it?

Password page is here:

http://www.ifieldhotels.com/availabilit ... bility.php

Password: test

Cheers,
Dave
davemarsh
 
Posts: 11
Joined: Wed Jan 07, 2009 2:08 am

Next

Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron