Many users, many calendars

Many users, many calendars

Postby texx » Tue Aug 04, 2009 11:26 am

Hey folks,

This is great, found the calendar a few weeks ago and i must say that chris did good work. It looks very professional and it is working very well indeed.

Now, for my requirements i would be happy to get a hint or a bit assistance from your side: Many user are loggin in into my side and all of them should see their own calendar to state their own availability (not the availability from a hotel or appartement). My first idea was to change the ID_ITEM to the USERNAME of the member. Therefore i made the changes in the functions.inc.php, update_cal.ajax.php and the BOOKINGS tables (renamed "id_item" to "username"). I also handover the username in a seesion to the calendar.php:

Code: Select all
<?php
include("include/session.php");
?>


I grabbed an Idea from the topic "login for member only". However, it doesn't work for me, even If i try to play with this part:

Code: Select all
if(isset($_REQUEST["username"]))
define("USERNAME",   $_SESSION["username"]);
else      define("USERNAME",   0);


Any Idea, how to include the USERNAME from the session in the scipt, so that people can see only their own availabilities?

Best regards, Texx
texx
 
Posts: 3
Joined: Tue Aug 04, 2009 10:46 am

Re: Many users, many calendars

Postby chris » Tue Aug 04, 2009 11:39 am

Hi there,
Thanks for the comments.

You "could" change the calendar table to save usernames rather than an id for each item but it is not a logical way to to it as this will take up more space (memory) and a username "might" change in the future whereas an id will always be the same and unique.

Can't you use the "id" of the users as the ID_ITEM?

If you have them logging in, you most likely have a db table with their data so, when they login, as well as saving their username as a session variable, save their "id".
something like this:
Code: Select all
$_SESSION["id_user"]=$row["id"];


Then, in the calendar script change the line where the ID_ITEM is defined to use this new session variable like this:
Code: Select all
define("ID_ITEM", $_SESSION["id_user"]);


In the ajax file, you just need to check that your (current) $_SESSION["username"] is set (apart for checking that you have the item id etc)

Not sure if any of this actually answers your question.... let me know if you need more specific help.

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

Re: Many users, many calendars

Postby texx » Tue Aug 04, 2009 12:08 pm

Hola chris,

Thanks for your reply, i really much appreciate your work for all the people...

Your are right, working with the ID instead of the username is a more efficient way. I will have a closer look to it this evening and let you know the result.

Best regards to sunny malaga, Texx
texx
 
Posts: 3
Joined: Tue Aug 04, 2009 10:46 am

Re: Many users, many calendars

Postby texx » Thu Aug 06, 2009 12:44 pm

Problem Solved!
So, as a solution for everyone who needs a separate calendar for any user. Every user can see and change only his own entries. In my special case the id_item row in the calendar table is used to store the user_ID from the current session:

First include the session of the user:
Code: Select all
<?php
include("include/session.php");
?>


Next is to define the constants and give a value:
Code: Select all
if(isset($_REQUEST["id_item"]))        define("ID_ITEM",    $_SESSION["user_ID"]);

Than we change the function like this:
Code: Select all
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item='".$_SESSION["user_ID"]."' AND MONTH(the_date)=".$month." AND YEAR(the_date)=".$year."";

Last is the ajax file. You need to change all of the following parts…
Code: Select all
WHERE id_item='".$_REQUEST["id_item"]."'

…to this:
Code: Select all
WHERE id_item='".$_SESSION["user_ID"]."'

I hope I did not forgot anything. Time will tell, but it works so far.
Thanks to chris, as usual he brings us back on track!
Greetings, Texx
texx
 
Posts: 3
Joined: Tue Aug 04, 2009 10:46 am

Re: Many users, many calendars

Postby chris » Thu Aug 06, 2009 12:57 pm

Hi there,
Thanks for outlining the steps that you took.

However, in theory it should just be enought to have defined the ID_ITEM with your session value:

if(isset($_REQUEST["id_item"])) define("ID_ITEM", $_SESSION["user_ID"]);

as the constant ID_ITEM is what is used for getting the calendar results.
By making those other changes, you have efectivley removed the need for the ID_ITEM constant.


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


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron