PHP - Updating data yearly. -Process advice- - php

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.

Related

Is mysql event scheduling the appropriate (or best) solution?

Basically i just want to know if i have the right idea or if a better one exists.
I have a database that stores auctions that are currently taking place on the website (or will do). Obviously there comes a point when the auction will end. I am pretty new to web developing and was just wondering the best way of changing the status of the auction in the database to "expired".
I am using phpmyadmin and mysql and have read a bit about mysql event schedulers. From what i can gather they seem like a good way of doing this. On this basis i surely just run a recurrent event every minute, say, and it checks the current time against the preordained finish time of the auction and then makes changes if need be? Is this correct? Also i can then move the expired auctions to an old archive - probably the best right idea do you think for optimum performance of my database?
Otherwise i just wondered if there was a better (or easier way) of doing the same thing. How do sites like ebay go about it for example? Thanks a lot for your time in advance.
P.S. I realize this is more of a conceptual question then anything specific. Nevertheless i hope its alright to ask!
You're way overcomplicating this. You don't need to actually change the status of the auction the moment it expires. The status is self-explanatory already from its expiry date. If you have a column expiry_time in the database, any time before that the auction is active, any time after it's expired. As simple as that. Use appropriate queries, like this to find all active auctions:
SELECT * FROM `auctions` WHERE `expiry_time` > NOW()
You could do it this way, but I would suggest another approach. This is something I've implemented myself (in a game, but with the same mechanics), and it worked like a charm.
The only thing you have to do is to run a function at every pageload (before anything else) and check if anything needs to be moved to the archive. If anything needs to be taken care of, do it.
If you do it this way, you know that the page the visitors are seeing always is updated. If you use some sort of cron_job or event like you talked about, some of those auctions might be "expired" a few seconds after the job is executed and is therefore displayed as incorrectly active for almost another minute.

Job planification: looking for UI design to make my own

I'm developping an admin panel with ExtJS.
I've almost finished it except one thing: I need the "partner" who logs in to be able to configure when he/she works.
I'm like re-inventing the wheel, but thanks to ExtJS and my structure this won't be a problem.
The actual problem is about UI design:
I want to make very simple so that it's possible to enter very simple values like "I'm working each working days from 8 to 12 then 14 to 18"
I want to make it more configurable and be able to precise "I'm on vacation from july,1st until august,31th"
I want to make it even more configurable and be able to precise "the month of january, I'm working every single day from 8 to 20 non-stop".
I was looking for some inspiration with Microsoft Scheduler but to be honest, a basic user will never ever (ever x 87) be able to use such a UI to configure when he/she works
Same for unix cronjob. From my point of view, this is very hard to understand from a basic user's point of view.
So my question is: do you know where I could find some inspiration for this? And maybe if there are some Php components well written out there to handle such things...
Here's the way I did it: a "list" of rows that contains:
start hour
end hour
start date
end date
and a list of associated days.
This way it's possible to configure any kind of scenarii, even though it requires a bit of thinking, because you do not have to enter it a "natural" way (= you usually think first days of week you work, the hours and maybe the start/end days = it's the opposite of my configuration).

calendar Question with PHP, reading your computer calendar

So I am really stumped because I have basic ideas but I am looking for some of your expertise.
What I am trying to do: I want to basically write an app using Twilio which you dont really need to know about because that is another issue. What that app does is call on a php file in my web host and "triggers the php code"
What I need help with here is how can I keep record in php of the calendar of the week for my computer. What I mean by that is if someone like an admin has a specific code that I have written for them, and that code runs automatically all week, but a specific week they dont want that code to run, instead they want a different code to run that week. How can I use php to find when a week has ended or keep track of the week using that calendar in bottom right of your computer screen so that my program will know after an admin wants a different code run from the usual code that the week is over no need to run that admin irregular code any more go back to your usual automated running code.
If you still dont know what I am talking. I will try to explain more. Think of 2 separate codes. One Custom and the other automated. The automated runs all the time automatically. But one day the admin chooses for that week he doesnt want to follow the regular shcedule of running the automated code as usual, instead for that week he would like to run the custom code and after the week is over go back to running the automated code as usual.
I hope that makes it more clear. I know that in PHP gives the date. But I really need expert opinion on how to do this.
Generally for something like this, I'd generate a "nextrun_datetime" for each and every script/user combination. By default it would have a repeat interval, in your case, 7 days.
If a user doesn't want to run it this week, they can "push" it out N days and the normal update interval would apply afterwards. To get the one-time shot, I'd allow an update interval of 0 or -1 to denote that.
With this sort of thing, whenever a script is updated (or saved, run, rescheduled), you can calculate the next date if there is one. From there, it's a relatively simple cron job that should check the last N minutes for any scripts to be run.
Unless your client machines are running on a completely different calendar than the server, why bother with wondering what the client's date is? Unless the client and server are in different time zones, the client date is going to be the same as the server date, except for a few hours around midnight.
As well, why depend on the client to trigger the server-side code? If this is a regularly occuring thing, use cron or whatever's available on the server to run the code automatically. If an admin wants to override WHICH code gets run, then you can provide an interface to change what's executed. Click a button on a site and a flag is set somewhere that tells the timed job to run script B instead of script A.
I've done something similar. Based on the day (e.g. monday, sunday) I would do something different in php.
this is how I did it:
$today = date('w');
if ($today== 0){
//its sunday
exec('rmdir C:\myApp\oldLogs');
}
else{
echo '1 -> monday, 2-> tuesday etc...'
}
you can also make a date from a string for example
$date = strtotime("8 days ago 14:00");
/*
or "Monday next week", "+1 week 2 days 4 hours 2 seconds","yesterday noon","10 September 2000" etc...
*/

Time tracking like Expert rating tests

I am trying to create an Online Quiz script like expert rating test on ODesk or Elance.
I want to track the time, means how much time have passed and left. I also want to stop the time counter, if the user internet connection is disconnected, so that he can start from where it was disconnected.
One last thing how to disable the last questions, which were attempted by the user. I am using PHP, MySql for it.
Your ideas will be great help for me.
Thanks in Advance
I've done something like this. Basically you have the right starting idea. Create a timer table which stores start times, test id and user id.
On each page load or AJax call you check the current timestamp minus the start time to see how long has gone since they started. If at any point it passes your limit you redirect them to the test complete page. Don't worry about the internet connection its actually irrelevant. This basic rule covers all.
I've done something related to this. you have to think about this to begin the idea. Create a timetable that stores begin the time, user id, or testing id.

suggestion regarding my "question of the week" project

I am going to start on a new project for my school. I have to create a "question of the week" forum, where the members can post questions and their questions could then be voted by other members. The best question of that week will be discussed the week after, and the posting of the questions will take place again.
I am going to use MySQL as database, with backend in php.
Does anyone have some examples of something that I could use? Also, how will I be able to see a week in my project? I mean, how am I going to decide that a week has passed? I can not figure that out.
Do let me know about your suggestions.
Thank you!
Best
Zeeshan
Pick a handful of the free php / mysql
forum software programs. These
should be a good starting point;
phpBB, Vanilla, SMF, BBpress.
Install
and configure each of them, and
figure out which one makes most sense
to you in terms of ease of use, ease
of customisation, etc.
You may find
that these forums have enough
features to achieve what you are
after without any extra effort, but
if not, then start customising!
To see a weeks worth of data, you would create a database query that would view only the current weeks questions posts. The algorith would look like:
Get current day
From the current day, find the last day of the week (you have to decide what you consider the last day of the week)
Subtract 7 days from the last day of the week
Write you query
SELECT * FROM questions WHERE postdate >= #7DaysFromLastDayOfWeek
Hope that helps and makes sense.
If you don't want to go the trouble of hosting your own solution (even if it is the implementation of a existing application), google have an application called Moderator which you can either use standalone or embed into another web page - not sure if this is suitable?

Categories