- Joined
- Jul 26, 2006
- Messages
- 3,626
- Reaction score
- 1,006
I have this project where I have to generate a new set of "shifts" every sunday. Right now I'm having the user do it manually by inputting the starting Sunday and then my script fills in until the next Saturday (e.g: user fills in "generate shifts from the [5th] of [June]" and then it'll generate shifts from the 5th (sun) until the 11th (sat) of June.
Shift generation:
The shifts have certain properties such as position, day, month, year, time (e.g: 6AM-4PM, etc.) and a unique ID. Day, month and year are in numbers and are in D-M-YY format (e.g: 6-6-11). I have arrays with their names, short format like Jun, Jul, Aug, etc. (so for the 6th month I'd do $month_names[$row["month"]-1] (-1 because the array starts at index 0, of course) and that would get me "Jun".
Now I want to automate this process so a new week of shifts is generated automatically every Sunday. I can't use a cron job if that is an option at all. It needs to be pure HTML/JS/PHP.
I'm not asking for complete scripts but just for a point in the right direction.
Thanks!
Shift generation:
PHP:
function generateShifts($day_start, $month, $year)
{
global $months, $month_lengths, $days, $times, $positions;
$f = 0;
$day = $day_start;
for($i = $day_start; $i < ($day_start + 7); $i++)
{
if($day > $months[$month-1]["length"]) //are we entering a new month?
{
$day = 1;
$month++;
}
if($month > 12) //are we entering a new year?
{
$month = 1;
$year++;
}
for($p = 0; $p < count($positions); $p++)
{
for($t = 0; $t < count($times); $t++)
$sql = mysql_query("INSERT INTO `shifts` (position, day, month, year, time, full_day) VALUES ('". $positions[$p] ."', '". $day ."', '". $month ."', '". $year ."', '". $times[$t] ."', '". $days[$f] ."')");
}
$f++;
$day++;
}
}
The shifts have certain properties such as position, day, month, year, time (e.g: 6AM-4PM, etc.) and a unique ID. Day, month and year are in numbers and are in D-M-YY format (e.g: 6-6-11). I have arrays with their names, short format like Jun, Jul, Aug, etc. (so for the 6th month I'd do $month_names[$row["month"]-1] (-1 because the array starts at index 0, of course) and that would get me "Jun".
Now I want to automate this process so a new week of shifts is generated automatically every Sunday. I can't use a cron job if that is an option at all. It needs to be pure HTML/JS/PHP.
I'm not asking for complete scripts but just for a point in the right direction.
Thanks!
Last edited:

