Cancel 1 instance of a repeating date - php

I've built a website for a local yoga studio (PHP). The site has a calendar. The instructor keeps needing to cancel a random class here and there. The problem is that we either have to cancel all the instances of a weekly repeating date to remove it from the calendar, or cancel none of them and hope that people read the announcements on the front page.
I'm trying to puzzle out how to have a mechanism where I can let her just cancel one instance of a weekly repeating date, but am neither able to comprehend the solution, nor to find anything on here that someone else has tried.
I have plenty of open source calendar scripts to hack up, and just need this one little feature. Any ideas?
Many thanks.

This is a not an entirely straightforward problem. You either need to:
To list all repeated dates in the database
To have a list of 'cancelled' dates in the database
How are the recurring dates currently implemented?

Related

PHP - Updating data yearly. -Process advice-

I have made an employee management system as such, and it calcualtes leave days. Although I am trying to work out how to make the leave days update yearly according to the staffs starting date.
I think I know how I will do this easily. Except it will involve the software being open on that date.
How would I account for each day, without the software having to be open?
Heres the process i was thinking:
-Loop through array of staff data and determine if starting date matches current date.
-If it matches then add an ammount of days to their leave days
I know this is very basic, and it has some flaws. Here are the flaws i am thinking:
-If the page were to be refreshed, or page opened again then it would add x2 of the staff days.
-Also, if the software was not to be opened on this day then the staff would not get the added leave days.
How would I get around this issues? I feel like it should be an easy thing, but I cant think on how to do it properly.
Any help would be greatly appreciated,
Create your php script I'll call it leavetime.php
Then if you have c-panel on your server, there is a thing called cron, in there you can select the time to call it. typically it will be something like this for the command
usr/bin/php -q locationof/leavetime.php
https://www.youtube.com/watch?v=ZAbefcWLxrw
As for the actual php code to do this, it's to broad a topic to cover in a single question.

Creating an advanced admin/staff rota [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know this place is for uploading code that may need some help although I hope you won't mind helping as I'm not sure where to really start with this code. You are the experts and I am a novice requiring help with future coding. If there is a section aimed at this kind of thing, I will be happy to repost.
Here is the situation:
I am starting work on an advanced admin backend panel for my staff, an idea I currently have is to use a MySQLi database to create the staff rota, to be displayed in a simple calendar like table on the aPanel.
Now, the advanced part is the staff member will be able to click "Clock In" or "Clock Out" during the times/days they are issued on the rota.
The system will NOT let the staff member Clock In, unless they are on the rota for that time of day. I will then have access to a management section of the panel allowing me to view the amount of hours the staff member has been clocked in for for if they have missed days, or are late, etc... And pay them for recorded clocked in hours.
Maybe some added features would be that they are clocked out automatically at the end of their shift or the system would record overtime and such?
I have no idea how I would go about creating such system or if it is actually possible so if anybody may have any advice/tips/examples for such idea I would appreciate any help!
All the best!
Your system will necessarily consist of several parts:
Database Store - Houses all necessary information for the system, Staff Schedules, Timeclock Entries, User Information, etc. Sounds like you already have this mostly in place, though it may need some tweaking for your purposes.
Staff Assignment / Admin Interface - System to allow administrators or those with appropriate access to assign schedules to Staff, add new Staff to the system, etc.
Timeclock Frontend - Staff would use this to login to view their schedules, and clock in/out.
(Possibly) Automated Monitoring System - If you wanted the system to automatically monitor active Staff, and clock them out when their schedule is up, you'll need a recurring task, a script that runs every X minutes and clocks out those Staff required.
This isn't a quick and simple project, but it's not very complicated either. The major pitfall you'll need to avoid is the temptation to just code the whole thing yourself. It may seem like a good idea at first, you only need a few hard-coded pages, right? Trust me, though, that process always ends in major headaches later on. Find a Framework that you can base your application on. It's a bit more to learn, but you'll be able to focus more on building your application, and less re-inventing the wheel.
For PHP, I strongly recommend Symfony. It uses Doctrine for it's ORM, which will make it much easier to handle data interactions, and Twig Templating, which is far superior to mixing PHP/HTML directly. Symfony has decent documentation, and a number of tutorials. (And an active Stack Overflow tag.)
Regardless of the choice you make, the best thing to do is choose a framework to base your application on, it'll make all the numerous little design decisions much easier. (And less error-prone for any widely used framework.)
Your individual questions are a little too vague to answer directly without a system around them. I'll try to give some general advice for them, though.
I am starting work on an advanced admin backend panel for my staff, an idea I currently have is to use a MySQLi database to create the staff rota, to be displayed in a simple calendar like table on the aPanel.
You might want to take a look at Full Calendar, a nice customizable JS calendar.
Now, the advanced part is the staff member will be able to click "Clock In" or "Clock Out" during the times/days they are issued on the rota.
When the employee logs in to the application, the application will load the schedule for that employee. If they have a current (or shortly upcoming) assignment, display a Clock In form. The Clock In form, on submit, will change the Employee status to Clocked In, and insert a timestamp into the Timeclock Logs associated with the Employee. If the employee is currently Clocked In, instead display a Clock Out form (possibly with shift notes), that does much the same thing, only switching the status to Clocked Out.
The system will NOT let the staff member Clock In, unless they are on the rota for that time of day.
It's fairly easy to check these sort of things after the Clock In form is submitted. If they aren't supposed to Clock In yet, throw an error. (Note, never assume that the pre-submission validations are sufficient. I.e., don't rely on the fact that the Clock-In form will only show up when the Employee can Clock In.
I will then have access to a management section of the panel allowing me to view the amount of hours the staff member has been clocked in for for if they have missed days, or are late, etc... And pay them for recorded clocked in hours.
In the admin section, you can create a report by getting all the Timeclock logs for a given employee for a given date range, total the hours worked, and compare to the expected schedule.
Maybe some added features would be that they are clocked out automatically at the end of their shift or the system would record overtime and such?
Have a script that runs every X minutes (lower times will have greater resolution, but consume more resources) as a scheduled task on your server, checking every Clocked In employee, and Clocking Out those who should no longer be Clocked In. If you're using Symfony, I'd recommend creating a Custom Console Command for the job.
That's hopefully enough to get you started. Please feel free to come back with any more specific issues that you may run into.

PHP / MySQL timetable comparison

I have an idea for a project that I am currently working on, I am however struggling to find a way to implement this in PHP/MySQL.
I have a database with a list of activities that a tattoo parlour has, basically he works from 9 to 5 and when an event is added it is added to the database using date and time
| --- DATE----- | TIME |
2012-11-02 ---| 10:00:00
What I am trying to do is list all the times and dates within the tattooist timetable in the following week that does not already have events going on, this will also ensure the tattooist doesn't double book too!
any assistance will help guys, any assistance will help
The best way to create the application is to store each scheduled event into a database and "black out" dates that are already taken by the applications "events" table (per say)... You will probably want to do your event creation checks during the point that the event would be created or written to the mysql db.... You will probably want to have an events table with a start and end time for each event.... when you go to schedule an event (assuming user input dictates event time and date) just write a mysql query that selects the event where the DATE(a.lastevent) = DATE(NOW())... let me know if you have further questions
Edit:
I would build the front end of the application calendar style using a JavaScript interface. In the long run it will be much more user friendly and much easier to create, I've implemented them in a day.
The framework I suggest using is ExtJS, there are many tutorials and extensions for calendars, I know that ExtJS 3 has a calendar built into it and you can view a tutorial on that here: http://www.sencha.com/learn/using-calendar
Additionally, if you decide to use ExtJS4, you can use this plugin: https://github.com/bmoeskau/Extensible/downloads or this one http://www.sencha.com/forum/showthread.php?142488-Extjs-4-based-open-source-Calendar-application
The second link is open source, the demo looks to be Spanish (it does what you need and more), but if you use Chrome you'll get a bar at the top asking if you want the page translated, click yes, it does a great job. From there you can do find and replaces to get it to English.
The ExtJS 3 tutorial will show you how to interface the calendar with a PHP page so that you can update your MySQL database via AJAX. It is much simpler than you might think, and you'll save a ton of time trying to code it from scratch.
Sometimes it depends on how long each scheduled event might be. Are you adding these events with just a timestamp or are you also tracking how long of a block is being assigned?
you could have an appointment set using a start and stop time and some math..
I have a annoying tendency to use a epoch timestamp instead of a mysql date time. then you can make calculations to see if an appointment overlaps or find the gaps. just have to learn to count in seconds or provide math to adjust :).

Building a one week calendar / schedule

My website involves scheduling recurring lessons and events. At present I have built a table using php and javascript which scans through my mysql DB, time slot by timeslot, day by day to see if there is an event scheduled or if the timeslot is free.
It works fine, but is quite clunky and ugly and to be honest, not user friendly enough. I have now built the rest of the site using JQuery along with php, JS, HTML.
I have searched far and wide for a JQuery module to sort me out for this, but every calendar/scheduler I find is for ongoing time, i.e. like the Outlook Calendar.
I want one that ONLY displays Monday - Sunday, with time intervals of a half hour - what's the best way for me to achieve this?
Many thanks in advance,
Brett
may be this can be of help if you haven checked it out already https://github.com/robmonie/jquery-week-calendar/wiki/

Best way to develop/manage/design recurring tasks/calendar

An example of what I'm talking about is similar to Google Calendar. When a new recurring task is created.
After creating the recurring task "template" - which all of the individual tasks are based on, do you create all of the individual tasks and store them in the database? or do you just store the "template" recurring events and their exceptions?
If the user requests a "month" view, and you want to display all of the events/tasks, it seems like creating the output in real time from the template, and including all of the exceptions would be a lot more resource intensive then if each individual recurring tasks was created from the template and inserted into the database.
This would make searching/sorting, etc, a lot more easier too.
Anybody create something like this before? ideas?
Store it all in the database.
You want to have a "Task Template" table and a "Task" table where there is a one->many relationship.
When the user indicates they want a task to reoccur, create a "Task Template" record and then create as many "Tasks" as the user has indicated (don't allow a user to create tasks too far into the future). Each Task is linked to the Task Template via a Foreign Key. The idea is that SQL is going to be more efficient at managing these records than trying to do this all in code based on one template. This way, you will have more option when your sorting and filtering your data. After all, writing a SQL query is easier than writing, testing, and maintaining a PHP function that manipulates the data.
Some other tips I would give you is:
Try to get a lot of information in your "Task Template" record. Keep the number of tasks the Template covers, the date the last task ends, the time elapsed between the first task and the last, etc.. This "Meta Data" can help save you query time when you're looking to sort and filter tasks.
Put an index on the Date and FK field, this will help query time as well.
I just built two calendar apps at work that were pretty well received by the bosses. I used the "FullCalendar" JQuery plugin (http://arshaw.com/fullcalendar/). I used JQuery AJAX to handle most of my events, and it had built in support for Month, Day, and Week view.
For recurring events I did the following a while back:
When a user entered an event I stored the event's date pattern GNU date style - the keyword for PHP is relative date formats.
Then I started off by creating events for e.g. the next year. And created actual records where I converted the relative date to an actual -- e.g. "every first Monday" to a "mm-dd-YYYY". This allowed me to display them and also allow the user to e.g. move a single event or cancel one, etc..
Then figure out how far to go into the future - my idea was to create events when the actual pages were browsed. E.g. if I had created events through June 2011 and someone skipped all the way to July 2011, I would iterate on my events and set them up transparently.
When the user changes the relative pattern, offer to update all following events -- unless they have a custom pattern already. Relative patterns make it super easy to calculate all that.
I went through the same problem a while back and instead of reinventing the wheel, I used Google Calendar APIs. (http://code.google.com/apis/calendar/data/2.0/developers_guide.html)
You create a Google Account and access the calendar information. There are APIs to create/edit/delete a recurring entry. Also, you can specify a date/time information and query for matching events.
When you create an event on Google Calendar, you will receive a token/id which you can store in your own database and reference it within the context of the application.
If the user requests a "month" view, and you want to display all of the events/tasks, it seems like creating the output in real time from the template, and including all of the exceptions would be a lot more resource intensive then if each individual recurring tasks was created from the template and inserted into the database.
I would disagree on that. What if a task repeats every saturday for the next 7 years... And what if there were a lot of these repeating tasks? That would cost you a lot of waste space. Therefor, I think it's better to save a recurring task as just one record + one record for every exception (since there are less exceptions than recurrences).
Well, the only problem left is how to set up a query to select each task (still thinking abou that)

Categories