NO LINK NEW LINK for AM and PM

NO LINK NEW LINK for AM and PM

Postby Lora » Thu Jun 25, 2009 6:01 pm

Hi Chris,

Awesome script. I've been playing with it for a couple of weeks. It's easy to use and tweak. http://test.snworks.com/daltonlegal/calendar.php

I followed your instructions for "Disabling update but keeping date selection". My booked days are not clickable for clients which is what I want ( I am using sessions for Admin).

If I select an available day, it loads my form "bookingform.php" just fine... The problem I have is that the partially booked days (available AM or available PM) are not linkable to the form.

Any suggestions?

Also, I do not want to show booking options for Sat or Sun. plus I would like to pass the selected date to the form


-Lora
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Re: NO LINK NEW LINK for AM and PM

Postby chris » Thu Jul 09, 2009 6:44 pm

Hi Lora, thanks for the comments.

Sorry on not getting back to you sooner on this one, I have been "away" from the forum for quite a while.

I am glad that you have got the admin and public version working using sessions to identify the administrator, just a question - have you also added this contol to the update_cal.ajax.php code? You must add this to prevent users from discovering and accessing the code directly (I am sure you have)

The problem I have is that the partially booked days (available AM or available PM) are not linkable to the form.

Any suggestions?

Interesting question and unfortunatley nothing immediatly springs to mind :(
Are you needing this for the "public" part where the user can request that half date?
If that where the case you could leave the half booked dates as clickable and use php to "detect" that the user was requesting the available space in the request form.

Making Saturdays and Sundays shouldn't be too hard.
In the php function draw_cal() where you have been modifying the code to make only available dates bookable you need to add some code to also detect the weekend days and define them as $show_link=0
Something like this:
Code: Select all
if( ($week_day==5) || ($week_day==6) )$show_link=0;

Note - not tested. also assumes that you have monday as first day of the week, you will need to adjust it if you have Sunday as first day.

Finally, passing the date to the form:
You have currently modified the code to be a simple href that links to bookingform.php. so that the available dates look like this:
<a href="bookingform.php" onclick="select_date ('2009-07-09');" title=" 07/9/2009" class="cal_day">
All you need to do is add the date to the link like this:
<a href="bookingform.php?date='2009-07-09" title=" 07/9/2009" class="cal_day">
By the way, you need to remove the javascript onclick="select_date ('2009-07-09');" from those links as the function doesn't exist in the page and is causing javascript errors.

Let me know if you need help with the exact code for the "half" days.

I hope my comments and pointers are of some help.
:)
Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: NO LINK NEW LINK for AM and PM

Postby Lora » Thu Jul 09, 2009 8:55 pm

Thank you for your response.

I do want to leave the half days clickable, but can't figure it out.
When the half days are clickable, the booked days become clickable too, otherwise, if I get the half days to be clickable (and not the booked days), then the available days are no longer clickable.

Hmm...
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Re: NO LINK NEW LINK for AM and PM

Postby chris » Thu Jul 09, 2009 9:05 pm

you need to check the state within the loop and activate the link if it is "am" or "pm"
Something like this:
Code: Select all
if( ($booked_days[$this_date]=="am") || ($booked_days[$this_date]=="pm") ) $show_link=1;


Without seeing your complete modified code I don't know exactly where this would need to fit in, paste your draw_cal() function here if you want me to take a closer look.

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

Re: NO LINK NEW LINK for AM and PM

Postby Lora » Thu Jul 09, 2009 9:38 pm

My network admin has php errors turned on (he won't turn them off) so I had alot of errors at first.
So, with a heads up on that, here is the code....


// create calendar for given month
function draw_cal($id,$month, $year, $booked_days,$show_link){

global $lang;

//create variable that was generating undefined error**************************************


$cal_no_day = "";

//create indexes that were causing undefined index errors**************************************
$lang[day_] = ("");
$lang[day_1] = ("");
$lang[day_2] = ("");
$lang[day_3] = ("");
$lang[day_4] = ("");
$lang[day_5] = ("");
$lang[day_6] = ("");
$lang[day_7] = ("");


// get bookings for this month for this advert
$booked_days = array();
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".ID_ITEM." AND MONTH(the_date)=".$month." AND YEAR(the_date)=".$year."";
if(!$res=mysql_query($sql)) die("ERROR checking id item availability dates");
while($row=mysql_fetch_array($res)){
$booked_days[$row["the_date"]]=$row["state"];
}
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Re: NO LINK NEW LINK for AM and PM

Postby chris » Thu Jul 09, 2009 10:05 pm

silly admin ;)
No need for that level of php warnings.


The bit of code that I would need to see is exactly the bit you have skipped ;)

ie. what happens in here:

$booked_days[$row["the_date"]]=$row["state"];
}

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

Re: NO LINK NEW LINK for AM and PM

Postby Lora » Thu Jul 09, 2009 10:15 pm

This part?...

// check if day is available
if(array_key_exists($this_date,$booked_days)){
//echo "<br>".$booked_days[$this_date];
if($booked_days[$this_date]=="am") $day_image='cal_am_'.$day_counter.'.png';
elseif($booked_days[$this_date]=="pm") $day_image='cal_pm_'.$day_counter.'.png';
else $day_image='cal_on_'.$day_counter.'.png';
}
else{
$day_image='cal_off_'.$day_counter.'.png';
}
// show ajax link or not****************************************************************

if (array_key_exists ($this_date, $booked_days))

//if($booked_days[$this_date]=="")

{


// day booked -No Link***********************************************************
$day_link_start = "";
$day_link_end = "";

} else {
//available - show new link************************************************
$day_link_start = '<a href="bookingform.php" onclick="select_date (\''.$this_date.'\');" title="'.$lang["day_".$week_day.""].' '.
$date_format. '" class="cal_day">';
$day_link_end='</a>';
}
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Re: NO LINK NEW LINK for AM and PM

Postby chris » Fri Jul 10, 2009 12:27 am

Yes, that's the bit.
Try changing this line:
Code: Select all
if (array_key_exists ($this_date, $booked_days))

with this:
Code: Select all
if( (array_key_exists ($this_date, $booked_days)) && ($booked_days[$this_date]=="on") )

That should remove the link on ONLY the "on" days, ie not the "am" or "pm" ones.

Not 100% this will work as I haven't got this set up to test but it looks right from here ;)

Chris

Edit.
Quite possibly this would also work:
Code: Select all
if ($booked_days[$this_date]=="on"))
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: NO LINK NEW LINK for AM and PM

Postby Lora » Fri Jul 10, 2009 2:54 pm

if( (array_key_exists ($this_date, $booked_days)) && ($booked_days[$this_date]=="on") ) enabled all of the links, including the booked days (people aren't suppose to be able to select the booked days, only the available, am and pm).

I tried the second snippet but I get an undefined index error and still, all of the links are clickable.


When I use...

if (array_key_exists ($this_date, $booked_days))

if($booked_days[$this_date]=="")

...then only the "am" and "pm" links are clickable but then the "available" link is disabled.
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Re: NO LINK NEW LINK for AM and PM

Postby Lora » Fri Jul 10, 2009 3:13 pm

I got it :D
I changed...

if( (array_key_exists ($this_date, $booked_days)) && ($booked_days[$this_date]=="on") )

to

if( (array_key_exists ($this_date, $booked_days)) && ($booked_days[$this_date]=="") )

Still having issues passing the selected date to the form, but haven't given up. I am using echo $this_date on the form but getting "this_date undefined" error.
Last edited by Lora on Fri Jul 10, 2009 4:10 pm, edited 2 times in total.
Lora
 
Posts: 16
Joined: Thu Jun 25, 2009 5:46 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron