Ajax Event Calendar Support Product Page

This topic is locked

How to show only users events? - Resolved

Asked 20 Jan 2011 01:13:50
1
has this question
20 Jan 2011 01:13:50 Christie Applegate posted:
In the topic started April 2009, Mario gave directions as to how to show only a specific user's calendar. I have been trying to get it to work but it either shows all of the appointments or none. Please help me find the error! Everything else is starting to come together nicely!

From calendar.php

jQuery("#dmxAjaxCalendar1").dmxAjaxCalendar(
{id:"dmxAjaxCalendar1", calendar_name:"Appointment Calendar", allowed_display_types:[true, true, true, true], legend_position:"top", display_type:1, events_type:[{number:0, name:"Daily Progress", color:"#FFFFFF", background_color:"#003366", border_color:"#003366", on_click:"MM_goToURL('parent','ptadaily.php?apptID=##id##');", on_mouse_over:"applyDMXTooltip(this,'url','updateappt.php?apptID=##id##','fade','easeOutQuad','mouse','out',100,100,'clickout','bluebevel',false,'','',0,0,'0','0','auto','auto');", on_mouse_out:""}, {number:1, name:"Missed Visit", color:"#000000", background_color:"#98FB98", border_color:"#98FB98", on_click:"MM_goToURL('parent','ptmissed.php?apptID=##id##');", on_mouse_over:"applyDMXTooltip(this,'url','updateappt.php?apptID=##id##','fade','easeOutQuad','mouse','out',100,100,'clickout','bluebevel',false,'','',0,0,'0','0','auto','auto');", on_mouse_out:""}, {number:2, name:"Discharge", color:"#000000", background_color:"#4169E1", border_color:"#4169E1", on_click:"MM_goToURL('parent','ptadischarge.php?apptID=##id##');", on_mouse_over:"applyDMXTooltip(this,'url','updateappt.php?apptID=##id##','fade','easeOutQuad','mouse','out',100,100,'clickout','bluebevel',false,'','',0,0,'0','0','auto','auto');", on_mouse_out:""}], google_feeds:[], ajax_feeds:[{url:"calendar_ajax/calendar_get_events1.php?link=<?php echo $_SESSION['kt_login_id']?>"}], week_start:1, use_working_hours:true, working_hours_start:8, working_hours_stop:17}       );



From: calendar_get_events.php

$query_filter = intval($_GET['link']);

$query_events = sprintf('SELECT `patient` AS title, `starttime` AS start, `stoptime` AS stop , `company` AS description, `appttype` AS type, `apptID` AS event_id FROM `appts` WHERE `filter` = %3$s AND UNIX_TIMESTAMP(`starttime`) <= %1$d AND (UNIX_TIMESTAMP(`stoptime`) >= %2$d OR (ISNULL(`stoptime`) AND UNIX_TIMESTAMP(`starttime`) >= %2$d))',$query_stop, $query_start),$query_filter;



Replies

Replied 20 Jan 2011 10:20:44
20 Jan 2011 10:20:44 Miroslav Zografski replied:
hello Christie,

You have some misplacements in your $query_events.
I will explain more detailed the solution provided for displaying events for a single user.
When you are trying to display events for a single user then that means you already have some means fro restricting access to the page where the calendar is and most often that is achieved with standard DreamWeaver server behavior.
That behavior uses a session variables to pass the id and/or the user name of the logged user while he browses the site content. So this is where the
<?php echo $_SESSION['kt_login_id']?>
comes from.

so once the ID is passed to the calendar_ajax/calendar_get_events1.php you need to $_GET it from the URL Parameter and assign it to a variable so you can use it in the $query_events.
Also you need to have a column in your database table for event that to content the id of the user that have added that event. Lets say that you have such a column and it is named `userID`.
Now how will the $query_events look like:

$query_filter = $_GET['link']; 


that is according to the name of the URL parameter you
have set in the calendar.php file -> calendar_get_events1.php?link=<?php echo $_SESSION['kt_login_id']?>
here comes the good part
once you have the user id passed from the calendar
you use it to filter the query

$query_events = sprintf('SELECT `patient` AS title, `starttime` AS start, `stoptime` AS stop , `company` AS description, `appttype` AS type, `apptID` AS event_id FROM `appts` WHERE `userID` = %3$s AND UNIX_TIMESTAMP(`starttime`) <= %1$d AND (UNIX_TIMESTAMP(`stoptime`) >= %2$d OR (ISNULL(`stoptime`) AND UNIX_TIMESTAMP(`starttime`) >= %2$d))',$query_stop, $query_start, $query_filter); 


Firstly you add in the beginning of the WHERE clause the name of the column that contains the user id values - in this case and as mentioned above that is `userID` column and it is equal to %3 - third parameter after the query; and $s - that parameter is treated as and presented as a string:
... WHERE `userID` = %3$s AND ...

Check the php manual for sprintf function
Second - you need to add the variable containing the user ID in the sprintf function as a last parameter so it will count as third. In this case that is the $query_filter variable:
...',$query_stop, $query_start, $query_filter);


And next you save the files and test your user id filtered calendar.

Regards,

Replied 20 Jan 2011 22:28:49
20 Jan 2011 22:28:49 Christie Applegate replied:
Got it!!! Forgot that if I set it as a Session variable, have to recall it as a session variable! Made the other corrections and it works! Thanks!!!!

Reply to this topic