Changing the users table

Hi, thanks for your excellent work on scheduler. I have a question about the mySQL database implementation:

Is it possible to edit the files so that the name of the users table can be changed, or is it possible to simply add extra fields to the existing user table, such as password/salt etc?

I have four flatmates and we all want to use scheduler as a sort of reminder/calendar, but we would all like to be able to log into our little site and be able to edit only our own entries while still being able to view each other. The log-in logic is already in place and scheduler is being added.

Would it be possible to add fields to the scheduler user table so that it could take over from our own user table (This would seem the simplest method). It would need to have several more fields so that it could be used in the log-on procedure.

My thinking would be that I could filter the user by ID (as I believe you do yourselves) and init scheduler according to the user, with the admin being able to edit everything etc.

Many thanks

Max

Tried to edit but…

Id also like to ask if it is possible to assign each user a different colour for their entries? This would make it easier for all of us to see what we are doing.

Is it possible for an admin to create an event for another user? and…

I currently have played with the collisions by adding dhtmlxscheduler_collision.js to my page - is this global? For example would user1 be able to create an event at the same time as user2? Is there a way to make this a per user setting if it is? (And would it still be possible for an admin to create events for different users, both at the same time?)

Sorry to be so long winded!

Regards

Max

Is it possible to edit the files so that the name of the users table can be changed
Are you referring to sample of multi-user usage? Or to WP|Joomla plugin functionality?

Normally scheduler has not any hardcoded expectation about table structure, you can have any custom fields and any names for default fields ( start, end, text ) as well. ( in case of plugin, renaming start_date, end_date, text fields is problematic )

In case of plugin, it can work in private-shared mode. When each user can see events of others but can edit only their own events.

is this global? For example would user1 be able to create an event at the same time as user2?
Yes it is.
There are some exceptions, if you have unit view based on users - in that view collisions for same time but different users will be allowed.

Thanks Stanislav.

No, its just a stand alone web page that I threw together with a PHP/mySQL backend and some jQuery at the front end.

At the moment we log in and out of it when we are at home, just to let each other know what is going on (We work/study at odd hours), but its clunky and not always easy to read - hence my desire to get the Scheduler in place.

What Id really like to be able to do is to log in as the admin (Just another user but with higher privileges for database access etc) and be able to make entries for each person. When any person, including myself as a user, logs on we can see and edit our own allocated entries, but not those of anyone else.

I can get each user to log in and edit only their own entries, but I cant seem to work out how to get the admin to be able to allocate an entry to a person. Does one of the examples show this, or is there a specific set of files that I can browse to work this out?

There are no custom views (units etc), just an agenda view, although Id like to use the reoccurring events at some point as well. Would this pose any problems?

Thanks again

Max

How odd! It seems that each user can add an event, and edit it, but when they return they are unable to edit their events - or any other users events. They can still make new events, and edit them, but only for that session!

Iv been taking code from ‘user1_combined.html’ from the examples folder, but somehow Iv messed it up and users cant edit anything! oops!

Iv collected the user ID when they log in, and have added this code for each user:

if(CurrentLoggedInUserID == 1) { scheduler.load("include/events.php?user=1"); scheduler.load("include/events_shared.php?user=2"); scheduler.load("include/events_shared.php?user=3"); scheduler.load("include/events_shared.php?user=4"); var dp = new dataProcessor("include/events.php?user=1"); dp.init(scheduler); function allow_own(id) { var ev = this.getEvent(id); return ev.userId == 1; } scheduler.attachEvent("onClick",allow_own); scheduler.attachEvent("onDblClick",allow_own); scheduler.attachEvent("onEventCreated",function(id) { var ev = this.getEvent(id); ev.userId = 1; ev.event_type = 1; }); }

There is a different section for each user and I think that this should allow each user to see shared entries (which is the default option) but only edit their own entries, but its not working.

Any ideas?

Cheers

Max

No, its just a stand alone web page that I threw together with a PHP/mySQL backend and some jQuery at the front end.

When you can use next approach ( probably you already have implemented most part of it )

  • add userid field to events table, include it in connectors to send to server side
  • alter saving code to insert userid for new events
    samples\02_customization\shared_events\events.php
    sample gets user_id from GET, but you need to take it from session ( GET approach is unsafe )
  • on client side, add onclick, ondblclick, onBeforeDrag handlers and return true from them only if current event has user_id same as logged in user
  • if you need to have secure solution - the same check need to be duplicated on server side ( as client side code can be easily cheated )
  • add event_class template , and return different class names based on userid - it will allow to define different colors for different users

To have superuser - create separate data feed, which will not have above security checks on server side and client side ( but will check in php code, that current user is superuser)

How to get the admin to be able to allocate an entry to a person
Assuming that you have a separate page for admin - you can add a select control in lightbox form and|or unit view to easily sort events
samples\03_extensions\02_units_view.html

they are unable to edit their events - or any other users events
Check that on server side you have userId in render_sql | render_table command.
If you are not providing userID as part of data feed - all events will be assigned to undefined user and as result not-editable.

Thanks for your reply, however, I don’t fully understand it all:

I can add the userid field to the events table, but I’m not sure what you mean by the rest of it!
Do you mean edit the events.php file to include the new userid field?

And how do I ‘alter saving code to insert userid for new events’ - where is the code?

Current user ID is taken from the session variables that I pass, so that should be no problem, but how would I do this:

I have done this, modifying the code to look like this:

[code]for(var i=0; i < CurrentUserCount; i++)
{
scheduler.load(“include/events_shared.php?user=”+CurrentUserArray[i]);
scheduler.templates.event_class=function(start,end,event)
{
for(var i=0; i < CurrentUserCount; i++)
{
if (event.userId == i) return “user_”+i;
}
}
}

var dp = new dataProcessor("include/events_shared.php?user="+CurrentLoggedInUserID);
dp.init(scheduler);
function allow_own(id){ var ev = this.getEvent(id); return ev.userId == CurrentLoggedInUserID; }
scheduler.attachEvent("onClick",allow_own);
scheduler.attachEvent("onDblClick",allow_own);
scheduler.attachEvent("onEventCreated",function(id){ var ev = this.getEvent(id); ev.userId = CurrentLoggedInUserID; ev.event_type = 1; });

[/code]

This lets me do everything in the loop rather than repeating it all, but the event_class function does not seem to work properly. I have ‘.user_1 div’ type classes in my css file that contain a background and text colour, but the div is not coloured properly - there is a coloured line beneath each item (behind it?) but not in the foreground.

Do you mean create another events.php file to call for the superuser?

No separate page for admin/superuser. Its the same scheduler showing, just the log in to the app is different. Above I asked if I needed to create another events.php file for the superuser - this is essentially that superuser - just another user whose userid is know beforehand, and that user is given admin privileges.

The render_sql has userid in it:

$scheduler->render_sql("select * from events_shared where event_type=1 AND userId = ".$user_id,"event_id","start_date,end_date,text,event_type,userId");

Is this correct?

Sorry to be such a pain - I’m a newbie at all things php, javascript and mysql and I’m trying to bumble through this and learn something on the way.

Many thanks for your time
regards
Max

And how do I ‘alter saving code to insert userid for new events’ - where is the code?
Related connector file, basically add userid to list of fields in the render_table or render_sql command , it will be enough to enable both loading and saving of that parameter.

The next is not so good

for(var i=0; i < CurrentUserCount; i++)
{
scheduler.load(“include/events_shared.php?user=”+CurrentUserArray[i]);
scheduler.templates.event_class=function(start,end,event)

For data loading

scheduler.load(“data.php”)

in data.php - just load all events without any filtering ( but include userid in list of fields)
as result you will load all data at once, and each will have related userid property

Next code is correct and will work as is.

scheduler.attachEvent(“onClick”,allow_own);
scheduler.attachEvent(“onDblClick”,allow_own);
scheduler.attachEvent(“onEventCreated”,function(id){ var ev = this.getEvent(id); ev.userId = CurrentLoggedInUserID; ev.event_type = 1; });

For css template

scheduler.templates.event_class=function(start,end,event) return "user_"+i; }

Assigned once, gives unique css class for events of each user

Do you mean create another events.php file to call for the superuser?
Yes, I will recommend to create a separate html page as well. It will makes thing a lot easier, to have separate js configuration on different pages, than mixing rules on a single page. (but in case of client code it is more aestetic than necessity)

Its the same scheduler showing, just the log in to the app is different.
If you are using the same page, be sure that above handlers for onClick,… are not assigned in case of superuser

Is this correct?
Yep, but check above suggestion about loading all events at once.

To consolidate above

  • single load command, which loads all events at once
  • client side rules to block action if event’s user differs from currently logged in
  • in case of superuser you can use the same server side and client code, just don’t use onClick, onDblClick, onBeforeDragHandlers
  • to assign user to event ( in superadmin mode ) - add select section in lightbox and map it to userid field

Stanislav you are a star!

Excellent job - I now have the users and superuser working exactly as I wanted.

Point taken - it has remained so far while I get things sorted out - Ill work on that next, thanks.

There is only ever a single page used with jQuery/ajax for pulling all the data - no page loads.
I keep all my JS in a single file (so far) and all my PHP function in a single file (again, so far). Unless I run into any serious issues with this Ill keep it this way because I find it a lot easer to work with.

Once again, many thanks for your time and help, and thanks for such an excellent product.

regards

Max