UNIQUE in Time fields (Avoid concurrent time) - php

I want to make a website that users can register for classes.
the rule is that one user can't register in one class that is concurrent with registered classes.
how can I implement it?
Is is solvable in query? or php code?

You can solve this problem using PHP and a query to your database. You will query the database to retrieve a list of Date-times for each registered course for that user.
Once you have the list, you can use PHP code to check if the time and day for the course the user is attempting to register for falls between any of the times in the list from the database.

Related

How to confing a database for multiple users with different data

I'm developing a web page where students, after registering, can introduce their school schedule, mark test and calculate averages. My problem is:
how do I do for each user to have their own schedule, calendar etc. I could be simple for you but I'm having difficulties solving this.
This is how I want schedules menu to look
all the data introduced for the schedule will show up on the table
You have to look at how a relational database works.
Everything you're trying to do is use a foreign key.
IMHO best way to achieve this is to register user ID+name in $_SESSION then, when he reaches the page, retrieve schedule from where it's stored. Depends also on the schedule/calendar format

Check in/out in attendance system using codeigniter

I am trying to build an online attendance system where employees sign in and check in daily except for weekends and vacations.
so , my idea was to create a daily attendance record as a table in the database.
Attendance_date_daily date
Employee_ID number(auto generated)
Check_in_time time
Check_out_time time
Attendence_status varchar
I am using codeigniter v 3.0.0
it's easy to create a model to get the current time and save it in the database when the user check in/out.
but the problem is that, if the user was absent for a day or more , then the system will not create a record for those days.
moreover, i can't create the records beforehand. since i don't know when the user will have his/her vacation and working days may differ.
what is the best way to create and manage those daily records?
One possible solution may be to allow the employees to do their check-in each day normally which would populate the database for those days.
In order to add the absence records for those who have not checked in you could use CRON or something similar to schedule a task at perhaps midnight each day. Use this task to target a url that would run a method in a controller that will check employees against the daily records. Obviously for those whom have checked in no action will be performed, although for those who have not and are not marked as on vacation or not working you update the database to add the absence records.
With a system like this you would typically invoke the url to perform the update using whatever system you use with wget or something similar to 'load' the url and force it to run. A security consideration also would be that you'll want to add in a secret key as a GET parameter or something similar so that the method can check that it's being invoked via the task and not e.g. someone visiting the url by comparing the GET parameter with a stored key that you've set.

How to assign a record to a person from a pool automatically using MySQL/PHP while preventing across assignment

I have a script that is written in PHP. It uses MySQL database to store records.
Basically, I have team of users that are making random calls to a different business. I want to add list of phone number in a queue "pool table". The system will need to assign the new call to the user. Now If a user is already working on a phone call I don't want another user to start calling the same number. I need a solution to prevent 2 people having the same record assigned to them. So if phone number 000-000-0000 is assigned to the user X the same record will be skipped and the next one in line get assigned to the next available user.
This table will be accessed a lot so I need a good solution that will prevent 2 people from working on the same record and also not cause system issues.
One way I can think of but looking for a better solution is
open transaction
select a call where record status is available
update that call by changing the status from records available to record pending.
commit transaction.
If the use completed the call then updated with a status of completed otherwise make the record available again.
what are other solution available for me?
Thanks
Without a little more information about the workflow, it's hard to know what to suggest, but it sounds like users are interacting with the application somehow while they are taking calls...true??
If so, you must have some way for the user to alert the system they are ready for a call.
ie...
I just started my shift... Deal me a number.
Or...
Submit notes from last call... click submit and Deal me another number.
In this scenario, it seems like it should pretty easy to just let the users "request" the next number. You could probably just insert the users id on that record so it shows in their queue.

Should I delete MySQL entries using a PHP script which users can run?

I'm currently working on a website which will have many users on it. These users are stored in a table with each having a unique id. The website will contain projects that the users can complete and these projects are stored in a separate table with unique id's as well.
I need to make the users have a page they can view which will display a list of all the projects they are currently working on.
To do this, I am going to set up another table in which each row will have the user's id as well as the project's id that they are working on. All of that will work alright but I would like to allow users to cancel their projects if they please. I am aware of how to do this, but I have read that deleting rows directly from a php script is insecure so the user used to access the database from PHP does not have 'DELETE' permissions. I am wondering if I should just delete rows at will when a user specifies which project to delete or if I should just have another field and simply mark each user-project row as being 'cancelled' in another field so I can work with them myself.
What you should do is, for maximum security is, have a parameter in the database table called "isActive", or something of that nature, that is a BIT data type to represent a boolean. If that boolean is false, then do not delete the project from the database, simply hide that tables data (do not display it on the site, but keep the data stored in the databse). That way, not only is your database secure from malicious users who would like to destroy data, but projects can also be "re-instated" if they wish to re-instate it. If the project sits around for a certain period of time, say, 14 days, just have the server delete it, not the user, if you wish. This worked for me in the past.
Hope This Helps!
The most common approach to this problem is to have a field in the table that can be used to mark a record as deleted. This would be the only access the general user would have to the table as far as deletion goes. Some people also have a full delete, which states clearly that it will never be accessible again after the operation is completed.
Personally, I prefer to retain full delete permission to administrators allow the user to only mark records as deleted. If you're concerned about space, add a last accessed field as well, and schedule at set intervals a call to perform a full delete on any records that are marked as deleted and have not been active for a certain amount of time.

How do I get a list of active users with PHP?

I currently maintain a DB table of users, when after logging in I update the table with their ID and login_time. This works to a point but currently I can't tell if the user has been active since the login or for how long.
Is there a better way to get a complete list of users that have been active in the past X minutes?
The best way to get what you need would be a "Last Activity" column in the users table. You would just update it whenever a user access a page. Depending on what information you need it could replace the login_time column or it could be a new column.
You'll have to keep track of when the user made their last request in your database as a separate table or column. You can then formulate a query to select, e.g. all users that have made a request in the last 5 minutes.
PHP itself does not store - or care for - that kind of information. Unless you happen to have your own session management module which does store this kind of information, then you could use data from that.

Categories