login for member only

Re: login for member only

Postby chris » Wed Apr 30, 2008 6:44 pm

STAGE 2 - restricting calendar links by user

So, if all has gone as planned, you should now be able to save the id_member in the calendar table.
Now we need to use this new info to restrict the calendar dates.

1. MODIFY ARRAY OF DATE DATA.
We now have this extra data that we need to add to the array that holds the calendar data and is used to draw the calendar.
In your main calendar.php file find this:
Code: Select all
$booked_days   =   array();
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".ID_ITEM."";
if(!$res=mysql_query($sql,$db_cal))   die("ERROR checking id item availability dates<br>".mysql_error()."<br>".$sql);
while($row=mysql_fetch_array($res)){
   $booked_days[$row["the_date"]]=$row["state"];
}

I am not sure which version you are using, instead of the above code, you might have this:
Code: Select all
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".ID_ITEM."";
if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates<br>".mysql_error()."<br>".$sql);
while($row=mysql_fetch_assoc($res)){
   //$booked_days[$row["the_date"]]=$row["state"];
   $booked_days[$row["the_date"]]=array("state"=>$row["state"], "id_booking"=>$row["id_booking"]);
}

Either way, replace with this:
Code: Select all
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".ID_ITEM."";
if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates<br>".mysql_error()."<br>".$sql);
while($row=mysql_fetch_assoc($res)){
   //$booked_days[$row["the_date"]]=$row["state"];
   $booked_days[$row["the_date"]]=array("state"=>$row["state"], "id_member"=>$row["id_member"]);
}



2.MODIFY draw_cal FUNCTION
You now need to open functions.php
I must admit that I am getting slight confused here as I have been working on several different mods at the same time and it is quite confusing.
However, I think that you are using the code for functions that I sent you via pm last week and I think that I "left in" a bit of code that I had done for another user that was actually quite similar to your needs (I actually thought that I had done it for you). If this is the case, we are in luck ;) with just a slight modification we can get this to work for you....
Find this code:
Code: Select all
if($booked_days[$this_date]["id_booking"]==$_SESSION["bookingID"]){
                   //   ONLY MODIFIABLE DATES
                   $date_alt      =   'BOOKING ID: '.$_SESSION["bookingID"].' '.$date_alt;
                }elseif($booked_days[$this_date]["id_booking"]>0){
                   // ie the date is booked by other
                   //   remove links from dates
                   $date_alt      =   $lang["day_".$week_day.""].' '. $date_format.' booked - You can not modify it.';
                   $day_link_start   ="";
                   $day_link_end   ="";
                }

and replace with:
Code: Select all
if($booked_days[$this_date]["id_member"]==$_SESSION["id"]){
                   //   ONLY MODIFIABLE DATES
                   $date_alt      =   'MEMBER ID: '.$_SESSION["id"].' '.$date_alt;
                }elseif($booked_days[$this_date]["id_member"]>0){
                   // ie the date is booked by other
                   //   remove links from dates
                   $date_alt      =   $lang["day_".$week_day.""].' '. $date_format.' booked - You can not modify it.';
                   $day_link_start   ="";
                   $day_link_end   ="";
                }

Well, that "should" be it..... if all has gone as planned, the calendar should now be restricted so that the member can only modify their own bookings and available dates.

MODIFIABLE BY ADMIN
You also mentioned that you need the whole calendar to be modifiable by the admin.
To do this you will need to identify some admin only session variable and in the draw_cal function you would need to condition the whole link block something like this so that, if it is admin, everything has links:
Find this (slightly above that last modifiaction):
Code: Select all
if($show_link==1){

and replace with this:
Code: Select all
 if(isset($_SESSION["id_admin"])){
            //   admin can modify all
            $date_alt       =    $lang["modify_availability_for"].' '.$lang["days"][$week_day].' '. $date_format;
               if($booked_days[$this_date]["id_member"]>0){
               $date_alt.='  - CURRENT BOOKING MEMBER ID: '.$booked_days[$this_date]["id_member"];   # add member id for info if booked
            }
            $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>';
          }
          else if($show_link==1)
          {

* where $_SESSION["id_admin"] needs to be a unique variable only available in the admin section.

Well, I realise that that is quite a lot of code to follow, let me know if you have any problemas and how it goes generally.

Thanks for the donation by the way, it is greatly appreciated :)

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

Re: login for member only

Postby aquado » Thu May 01, 2008 2:09 am

Hello there,

I've implemented all your changes. But it's not working yet...
All the records in db in column "id_member" have value = 0. I've logged to the calendar (as two diffrent users) and was able to change all the dates even those already reserved or booked.
Maybe it's joomlas fault.
I'll try to make my own login system and test this solution once again. Maybe it'll help.

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

Re: login for member only

Postby chris » Thu May 01, 2008 10:56 am

I suspect that there is some problem with the Joomala integration

Can you try doing echo $_SESSION["id"]; in the calendar page just to confirm that we have this value?

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

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron