login for member only

login for member only

Postby LionUk » Fri Apr 11, 2008 8:22 pm

hello i am deaf, i am newbie here...
i found your so great but i wonder what i want is
people as customer view can see calendar but cannot try change them availability calendar
only member login (code) that they can change availability calendar...
(multi member) (agentID# where # id number for login)

hope you know what i mean?

thank you

p.s. i will pay donate if all work great what i want above....
LionUk
 
Posts: 3
Joined: Fri Apr 11, 2008 7:49 am

Re: login for member only

Postby chris » Fri Apr 11, 2008 8:49 pm

I there and welcome to the forum ;)

Sorry I missed this one - I haven't checked the forum for a couple of hours.
I have sent you a pm in answering the one that you sent me. However, if possible I will try to give any script solutions/adaptions here in the forum as they may well be of help to others - you never know ;)

Chris

PS. any donations are always welcome ;)
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 LionUk » Fri Apr 11, 2008 9:11 pm

yes i have sent you already on your PM ;)
LionUk
 
Posts: 3
Joined: Fri Apr 11, 2008 7:49 am

Re: login for member only

Postby chris » Fri Apr 11, 2008 10:03 pm

OK,
As I said, I will post this here in the forum so as to hopefully be able to help others with the same needs...

You want your members to be able to modify their "own" calendars but not others.

From your pm I now know that you have a login system working for the other "private" functions so that is one thing out of the way :)

I presume (hope) that you are using $_SESSION variables to validate the user on each page - is that correct?
I also suspect (again hope) that one of these session variables holds the "agentID".
If so, you can then update the calendar code (the main file) so that the ID_ITEM uses this value (currently in the code it uses a hardcode or $_REQUEST value.
So, you need to find this code:
Code: Select all
if(isset($_REQUEST["id_item"]))    define("ID_ITEM",$_REQUEST["id_item"]);   #id sent via  url, form session etc
else      define("ID_ITEM",   6);   #   default used for demo

and replace it with somthing like this (depending on the name of you session variable):
Code: Select all
if(isset($_REQUEST["id_item"]))
{
  define("ID_ITEM",   $_REQUEST["id_item"]);   #   id sent via  url, form session etc
  define("ALLOW_UPDATE", "0");
}
elseif(isset($_SESSION["agentID]))
{
  define("ID_ITEM",   $_SESSION["agentID]);   # default used ;
  define("ALLOW_UPDATE", "1");
}
else
{
  die("NO ID SET");
}

This will do one of 3 things:
Firstly, if the calendar is being used to show the dates of "another" member - ie the $_REQUEST["id_item"] has been defined via an url, form etc then it will show the uneditable calendar for that member.
It also sets a new constant "ALLOW_UPDATE" to 0 which we will use later to tell the calendar that it can't be modified

Otherwise, if the user is logged in, it will use their "session id" to define which calendar to show.
In this case the "ALLOW_UPDATE" constant is set to "1" meaning that the calendar CAN be updated.

Finally the third case is to catch any errors if we don't have any id for the calendar OR if the user is not logged in (ie no session variables set)


OK, so now we have to modify the calendar to accept the new "ALLOW_UPDATE" constant...
Fortuantly the code is actually prepared for this though so it is just a question of finding this line:
Code: Select all
draw_cal(ID_ITEM,$val["month"], $val["year"], $booked_days,1)

and replacing it with this:
Code: Select all
draw_cal(ID_ITEM,$val["month"], $val["year"], $booked_days,ALLOW_UPDATE)

Here, the only difference is that we have replaced the hardcoded "1" value at the end to this new constant

Now, in theory, your calendar should accept work as required as regards the ability to modify calendars by users.

See if you can get this working before we move on to the next question - preventing previous months being shown.

I hope you can follow my instructions ;)


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 LionUk » Fri Apr 11, 2008 10:20 pm

member can fill availabity calendar, as edit page or whatever = yes
public cannot fill it, just view = yes

thank
LionUk
 
Posts: 3
Joined: Fri Apr 11, 2008 7:49 am

Re: login for member only

Postby chris » Fri Apr 11, 2008 10:28 pm

So, can I take it from your response that you have been able to follow and implement my changes?

The next step is to modify the calendar so as the be able to jump move forwards and backwards through the months.

As I mentioned in the pm, take a look at my post here which explains exactly how to modify the calendar to accept this feature.
Once you have got that working we will just have to adjust the code to not show months previous to the current one.

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

Changes for members only

Postby aquado » Tue Apr 29, 2008 1:17 pm

Hi Chris,

I wanted to allow users to log to the calendar via Joomlas "Login form" to use it the way you was describing above (logged users can book free days or change only their reservations). Can you please help me and tell me what changes are needed to make it work?

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

Re: login for member only

Postby chris » Tue Apr 29, 2008 2:28 pm

Hello again,
I wanted to allow users to log to the calendar via Joomlas "Login form" to use it the way you was describing above (logged users can book free days or change only their reservations). Can you please help me and tell me what changes are needed to make it work?

I'm afraid that I have no idea of how joomala works.
You will need to check the session variables that it creates when a user logs in (try print_R($_SESSION) and identify which one you require for the calendar to use as ID_ITEM. I am sure that joomala will have something like $_SESSION["id_user"].

Once we have that we need to adjust the code that I outlined below as that was for getting seperate calendars for each user. From what I understand in your latest post, what you actually want is just one common calendar for all members where they can book any days, change their own bookings but not change any days booked by other memebrs. If the user is not logged in, they can only view the calendar but not modify anything.

Is this correct?

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

Changes for members only

Postby aquado » Tue Apr 29, 2008 4:37 pm

Yes, you got my idea exactly.

There should be possibility for admin to make any changes in the calendar he wishes to do.
As far as I can establish joomla references its users in this way:

Code: Select all
$user = &JFactory::getUser();                                <-- PEAR syntax
$userid = $user->id;


The output from: print_R($_SESSION) gave:
Code: Select all
Array ( [__default] => Array ( [session.counter] => 7 [session.timer.start] => 1209535895 [session.timer.last] => 1209536056 [session.timer.now] => 1209536056 [session.client.browser] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070208 Mandriva/2.0.0.6-12mdv2008.0 (2008.0) Firefox/2.0.0.6 [registry] => JRegistry Object ( [_defaultNameSpace] => session [_registry] => Array ( [session] => Array ( [data] => stdClass Object ( ) ) ) [_errors] => Array ( ) ) [user] => JUser Object ( [id] => 64 [name] => john smith [username] => aquado [email] => aquado@t2.com [password] => 66505c210b4c0c03070f349:bcc2dac4f [password_clear] => [usertype] => Registered [block] => 0 [sendEmail] => 0 [gid] => 18 [registerDate] => 2008-04-29 12:30:27 [lastvisitDate] => 2008-04-29 13:22:11 [activation] => [params] => [aid] => 1 [guest] => 0 [_params] => JParameter Object ( [_raw] => [_xml] => [_elements] => Array ( ) [_elementPath] => Array ( [0] => /var/www/joomla/libraries/joomla/html/parameter/element ) [_defaultNameSpace] => _default [_registry] => Array ( [_default] => Array ( [data] => stdClass Object ( ) ) ) [_errors] => Array ( ) ) [_errorMsg] => [_errors] => Array ( ) ) [session.token] => d78227e783fb6a8fa6570b52a11b5dff ) )


Code: Select all
[user] => JUser Object ( [id]

So the variable to identify user will be "id".

I'm not sure if it'll help you but the code for the db tables that I think should correspond with each other is as follows:
Code: Select all
CREATE DATABASE IF NOT EXISTS joomladb;
USE joomladb;

--
-- Definition of table `joomladb`.`bookings_calendar`
--

DROP TABLE IF EXISTS `joomladb`.`bookings_calendar`;
CREATE TABLE  `joomladb`.`bookings_calendar` (
  `id` int(10) NOT NULL auto_increment,
  `id_item` int(20) NOT NULL default '0',
  `the_date` date NOT NULL default '0000-00-00',
  `state` char(6) NOT NULL default 'all',
   PRIMARY KEY  (`id`),
  KEY `id_item` (`id_item`)
) ENGINE=InnoDB AUTO_INCREMENT=218 DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `joomladb`.`jos_users`;
CREATE TABLE  `joomladb`.`jos_users` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `username` varchar(150) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',
  `usertype` varchar(25) NOT NULL default '',
  `block` tinyint(4) NOT NULL default '0',
  `sendEmail` tinyint(4) default '0',
  `gid` tinyint(3) unsigned NOT NULL default '1',
  `registerDate` datetime NOT NULL default '0000-00-00 00:00:00',
  `lastvisitDate` datetime NOT NULL default '0000-00-00 00:00:00',
  `activation` varchar(100) NOT NULL default '',
  `params` text NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `usertype` (`usertype`),
  KEY `idx_name` (`name`),
  KEY `gid_block` (`gid`,`block`),
  KEY `username` (`username`),
  KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8;



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

Re: login for member only

Postby chris » Wed Apr 30, 2008 5:56 pm

OK, lets see if we can get this to work ;)

PART 1 - ADDING THE USER ID TO THE CALENDAR BOOKING

1. ADD NEW COLUMN TO DATABASE CALENDAR TABLE:
If you have phpAdmin, run this code in the sql form:
Code: Select all
ALTER TABLE `bookings_calendar` ADD `id_member` INT( 10 ) NOT NULL ;

ALTER TABLE `bookings_calendar` ADD INDEX ( `id_member` ) ;

This will add a new column where we are going to save the id of your members

2. IDENTIFY LOGGED IN USER OPTIONAL IF REQUIRED.
In case you are opening up this calendar in a completely seperate new window, ie without all the joomala code, you will need to add this line at the beginning of the page (directly after the <?php ) to start the session (it should continue the current one started in joomala)
Code: Select all
session_start();


3. MODIFY THE AJAX TO SAVE THE MEMBER ID WHEN MAKING BOOKINGS
Now, in update_cal.ajax.php we need to modify the mysql insert code so that it saves this new information (id of the member)
At the very beggining of the code, directly after the opening php tags (<?php) you need to add this line to keep the session from the calendar page:
Code: Select all
session_start();

Then, find this line:
Code: Select all
$insert="INSERT INTO ".T_BOOKINGS." SET id_item='".$_REQUEST["id_item"]."', the_date='".$_REQUEST["the_date"]."', state='".$_REQUEST["special_state"]."'";
      

and replace with this:
Code: Select all
$insert="INSERT INTO ".T_BOOKINGS." SET id_item='".$_REQUEST["id_item"]."', the_date='".$_REQUEST["the_date"]."', state='".$_REQUEST["special_state"]."', id_member='".$_SESSION["id"]."'";


OK, time for a break, if you have been able to follow and implement these steps, you should now be able to test your calendar (remember to login first) and make a booking. Once you have done that, check in your database that the booking has been made with your member id.
Next stage is going to get interesting as there we are going to have to modify the draw_cal function so as to use this MEMBER_ID to decide which days are modifiable. However, I don't think that it will be too hard.
Let me know when you have complete this stage and I will move on to the next one ;)

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 2 guests

cron