Help with Multiple Properties

Help with Multiple Properties

Postby dewhickey » Wed Jan 28, 2009 1:02 am

I Have been through the entries that are already on the forum for Multiple Properties, but I'm just not getting it. Where in the code do I add the form? How do I get it to fit above "Num months to show" and "Language" drop downs? Secondly, do I need to add a separate table in my database for each of the properties? Does anyone have an example of the code that handles calendars for more than one property? It would be much appreciated. Thanks.
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Help with Multiple Properties

Postby chris » Wed Jan 28, 2009 9:28 am

Hi,

No, you don't need to add anything to the database (as regards the calendar code) to be able to handle multiple properties.
The calendar table has a field "id_item" that will accept any id that it receives.

An example of how to change the property to show might be something like this:
Code: Select all
<select name="id_item">
<option value="1">Property 1</option>
<option value="2">Property 2</option>
<option value="3">Property 3</option>
etc.
</select>

Though I think that in most practicle terms the normal use would be to just pass the it_item in the url from the property in question.
For example, you have a page defining the individual property details. On that page you have a link to the property availability calendar that says something like "check availability".
The link for that calendar would be something like this:
Code: Select all
<a href="calendar.php?id_item=2">check availability</a>
where the "number" would be the id of the property in question.

I hope this helps

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

Re: Help with Multiple Properties

Postby dewhickey » Wed Jan 28, 2009 5:14 pm

As always, I was trying to make this more complicated than necessary. In fact, I didn't need to make any changes in your PHP script, at all. On the public side, I put a link to the private side where the calendar gets edited. When that link is clicked, the login form pops up. If the user puts in a valid ID and password, he's taken to the edit calendar page which is simply called by adding "?id_item=3" or "=4" or "= whatever number I'm using for each individual property." You see, for my purposes, I don't want the back-end users to have access to all the calendars. I have a different person handling each calendar.

Oh, yes, I will make one change on the calendar index.php page. When a user makes it past the login form, index.php will return a value assigned by the login form as a variable and use that to test which id_item number he has access to. That way, after he gets to his assigned calendar, he won't be able to go up to the address line and get away with being able to just change the id-item number to move to a calender he shouldn't have access to.

This is all amazingly simple. (Although, after reading what I just wrote, it doesn't sound simple. It's kind of early in the morning. Maybe I should have had another cup of coffee before writing this response.)

So, anyhow, thanks again. This stuff is great.

P.S. If you ever get around to adding the ability to show events associated with selected dates, that would be terrific. I have a couple clients who are golf courses. I have calendars for them that let the public know when the course is closed because there is a private outing or tournament. But I currently hand code those calendars using html, which is kind of a hassle. I could use your availability calendar to show when the course is closed for public play, but I'd still have to hand code html to explain why it's closed.

Thanks again for your help.
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Help with Multiple Properties

Postby chris » Wed Jan 28, 2009 8:16 pm

You could add a "comment" to the date that is clicked in the following way (without rewriting the code that is)

1. Add a new field to the calendar table:
Code: Select all
ALTER TABLE `calendar_table` ADD `comments` VARCHAR( 255 ) NOT NULL

if you want to do this directly in your code without needing to open up pmpadmin add these lines:
Code: Select all
$sql="ALTER TABLE `".T_BOOKINGS."` ADD `comments` VARCHAR( 255 ) NOT NULL";
mysql_query($sql) or die("error");

* Remember to remove them once you have called the page in the browser once!

2. Create a text field on your calendar admin page with the id (eg) date_comment:
Date Comment: <input type="text" id="date_comment" size="30">

The idea being that, whatever is written in that input field will be added to the database table for that date.

3. In the /js/update_cal.js file we need to get this text value and apend it to the ajax url.
Somewhere towards the beginning of the draw_cal() function add this line:
Code: Select all
date_comments=document.getElementById('date_comment').value;

Then, further down the code add this variable to the ajax url like this:
Code: Select all
var the_url=update_url+"?id_item="+id_item+"&the_date="+the_date+"&special_state="+special_state+"&date_comments="+date_comments


You can use alert(the_url); directly after that line to check that the comments are being passed.

4. In update_cal.ajax.php we now need to add this data to the calendar table for the date.
Update both the insert and update queries where we are adding or updating the date by adding this:
Code: Select all
, comments='".mysql_escape_string($_REQUEST["date_comments"])."'

be careful with the update option.... you might overwrite previous comments.... but I will let you think about that for now ;)


If all has gone well we should now have those (optional) comments saved in the calendar table alongside the corresponding date.

The final thing we need to do is somehow show this information to the user who visits the calendar and sees the date booked.
I don't know what you have right now but perhaps the simplest method might be to use the "title" tag for the dates so that when the user rolls over them with the mouse, the comments are shown.

To modify this, open includes/functions.inc.php
5. First we need to change the array that is created when we check the months dates.
Change
Code: Select all
$booked_days[$row["the_date"]]=$row["state"];

to this:
Code: Select all
$booked_days[$row["the_date"]]=array("state"=>$row["state"],"comments"=>$row["comments"]);

You will see that we have restructured the array to include the comment, so now we have to modify the code that decides which "state" to show below.
6. Find these lines:
Code: Select all
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';

and change to this:
Code: Select all
if($booked_days[$this_date]["state"]=="am")      $day_image='cal_am_'.$day_counter.'.png';
elseif($booked_days[$this_date]["state"]=="pm")   $day_image='cal_pm_'.$day_counter.'.png';

7. Finally find the loop where the actual dates are shown:
Code: Select all
$the_cal .= '
         <td class="cal_data" '.$border.'>
            '.$day_link_start.'
            <span id="state_'.$this_date.'">
               <img src="'.DIR_IMAGES.''.$day_image.'" alt="'.$lang["day_".$week_day.""].' '. $date_format.'" border="0"  width="20px" height="20px">
            </span>
            '.$day_link_end.'
         </td>
         ';

And change to this:
Code: Select all
if($booked_days[$this_date]["comments"]!="")   $date_title=$booked_days[$this_date]["comments"];
         else   $date_title=$lang["day_".$week_day.""].' '. $date_format;
         $the_cal .= '
         <td class="cal_data" '.$border.'>
            '.$day_link_start.'
            <span id="state_'.$this_date.'">
               <img src="'.DIR_IMAGES.''.$day_image.'" alt="'.$lang["day_".$week_day.""].' '. $date_format.'" title="'.$date_title.'" border="0"  width="20px" height="20px">
            </span>
            '.$day_link_end.'
         </td>
         ';


Fingers crossed that should all work.

I realise that there are quite a few changes to make, but if you take your time it should all work out ok - I have just tested it on a test version and it worked as expected.

Let me know how it goes ;)

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

Re: Help with Multiple Properties

Postby dewhickey » Wed Jan 28, 2009 8:21 pm

Wow, thanks. It looks like I have my work cut out. I'll go through this as soon as possible and post back. Thanks again.
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Help with Multiple Properties

Postby chris » Wed Jan 28, 2009 8:32 pm

now, thinking about it it might be "nice" to use a different color for the days booked for events by using a differnt key-mouse combination....
Maybe one for another day ;)

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

Re: Help with Multiple Properties

Postby dewhickey » Wed Feb 04, 2009 5:06 pm

I've been kind of busy with other work, so I'm just now getting back to this. I spent a few hours very carefully adding/changing all the snippets of code you provided above for adding comments to dates. However, I've obviously done something wrong. When I open index.php in Firefox, the calendar is properly displayed, and it shows the new form text field for typing in the comment in a new table row I added under the select number of months to show drop-down list. But when I select a date, the date number is replaced with that little animation of circling arrows. That's it. The arrows just go on circling. It's not making it to the next step. I wonder if I've put something in the wrong place.

You said you added it to the test version on your end, and it worked fine. Do you still have that version with the comment capability included? Do you think you could provide a way to download that version. I'd love to go through it and compare it with what I've done. That would be very instructional.

Thanks
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Help with Multiple Properties

Postby chris » Wed Feb 04, 2009 11:15 pm

Hello again,
I have sent you a pm with the zip file (link) with the changes I made.

If you are just getting the "loading" image, that probably means that there is an error in the php ajax file that is causing it to not return anything to the javascript file.
Check the code that you have modified in the update_cal.ajax.php file, I wasn't very explicit in my explanation as to what to modify in that file, sorry :oops:

Let me know how it goes.

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

Re: Help with Multiple Properties

Postby dewhickey » Thu Feb 05, 2009 12:55 am

Well, I created a new folder and unzipped the files you sent me. I browsed to the index.php file in Firefox. I entered "test" in the comment box. When I click on a date I get two error messages.

First I get this in a pop up: ./update_cal.ajax.php?id_item=2&the_date=2009-02-06&special_state=&date_comments=test

When I close that error, I get another error: ERROR INSERTING. INSERT INTO bookings_calendar SET id_item='2', the_date='2009-02-13', state='', comments='test'<br>Unknown column 'comments' in 'field list'

Nothing with PHP ever goes smoothly for me. Well, sometimes I do get it right.

By the way, I get an error when I try the page on the URL you sent me, too.
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Help with Multiple Properties

Postby chris » Thu Feb 05, 2009 2:25 am

Opps, in my version and the zipped version I have left an "alert" in the javascript file.
Find and remove this line in update_cal.js:
Code: Select all
alert(the_url);
Code: Select all


Secondly the php error you are getting is because, as the error suggests, you don't have the "comments" field in your calendar table in the database.
Have you not added it yet with the code I mentioned earlier?

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

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron