1

I am trying to make an appointment calendar and I am using html table for to do this. I want a situation where if a user clicks an empty cell (time slots e.g. 8:00 or 8:15 are divided into cells using ), a form pops up and the user fills the form. After the user fills the form, the form data is saved into a database. But if a cell slot has already been filled by a particular user, the data of that slot should be accessible to that user and greyed out to other users. If the cell is empty, it should make the cell clickable to everyone. But if the cell is not empty, that is, a user already booked an appointment in that cell, it should allow the cell to be clickable by only the user and admin and should not be clickable to other users. And also the user should be able to edit the content of the cell.

How do I go about this? I am using PHP and JavaScript.

Below is what I have done so far.

if($_SESSION['interval'] == 30)
{
    echo "<td onclick=popUpForm('$hoursDisplay[$x]:00-$hoursDisplay[$x]:30','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:30-".$hoursDisplay[$x+1].":00','$date')>&nbsp;</td>";
}

if($_SESSION['interval'] == 20)
{
    echo "<td onclick=popUpForm('$hoursDisplay[$x]:00-$hoursDisplay[$x]:20','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:20-$hoursDisplay[$x]:40','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:40-".$hoursDisplay[$x+1].":00','$date')>&nbsp;</td>";
}

if($_SESSION['interval'] == 15)
{
    echo "<td onclick=popUpForm('$hoursDisplay[$x]:00-$hoursDisplay[$x]:15','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:15-$hoursDisplay[$x]:30','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:30-$hoursDisplay[$x]:45','$date')>&nbsp;</td><td onclick=popUpForm('$hoursDisplay[$x]:45-".$hoursDisplay[$x+1].":00','$date')>&nbsp;</td>";
}
Abbas
  • 6,415
  • 4
  • 31
  • 49
Bee Square
  • 11
  • 1
  • 1
    The code example that you have added is not complete and cannot be run without extensive editing. Please add a proper code example. Also, do you have a specific question or do you want to know how to make an entire PHP/JavaScript calendar? – Abbas Dec 24 '11 at 21:17

2 Answers2

0

Once the user logs in, set a cookie. When a request comes for an empty cell serve the form, otherwise check the cookie to authenticate the user. If the cookie doesn't match then give an error. Login authentication is covered here

Community
  • 1
  • 1
Steve C
  • 637
  • 3
  • 6
0

As user has to be logged in to be identified you should simply serve the good html cell code regarding the user state. Lets imagine you have a session with thoose datas:

$_SESSION = array('userId'=>1,'isAdmin'=>false);

then checking if you have appointment or not, and if the user is owner of the appointment or admin you can know easily wich version of the cell you have to render (clickable or not).

There's no need to make a particular use of javascript here as all datas are available server side at render time i imagine.

Your question is too vague and should be precised a bit if you want us to respond more precisely on a point.

malko
  • 2,137
  • 15
  • 23