Automation
<p>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.</p>

<p>Shift generation:
PHP Code:</p>

<pre><code>function generateShifts($day_start, $month, $year)
{
    global $months, $month_lengths, $days, $times, $positions;
    $f = 0;
    $day = $day_start;
    for($i = $day_start; $i &lt; ($day_start + 7); $i++)
    {
        if($day &gt; $months[$month-1]["length"]) //are we entering a new month?
        {
            $day = 1;
            $month++;
        }
        if($month &gt; 12) //are we entering a new year?
        {
            $month = 1;
            $year++;
        }
        for($p = 0; $p &lt; count($positions); $p++)
        {
            for($t = 0; $t &lt; 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++;
    }
} 
</code></pre>

<p>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".</p>

<p>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.</p>

<p>I'm not asking for complete scripts but just for a point in the right direction.</p>

<p>Thanks! </p>
