<?php
//path to styles
$directory = "styles/";
$cssExists = true;
$i = "";

//Today
$today = date('Y/m/d');
$todayArray = explode("/", $today);
$yearNum = $todayArray[0];
$monthNum = $todayArray[1];
$dayNum = $todayArray[2];
$currentWeek = date('W',strtotime($today));

//Yesterday
$yesterday = strftime("%Y/%m/%d", mktime(0, 0, 0, date('m'), date('d')-1, date('Y'))); 
$yesterdayArray = explode("/", $yesterday);
$yesterday_yearNum = $yesterdayArray[0];
$yesterday_monthNum = $yesterdayArray[1];
$yesterday_dayNum = $yesterdayArray[2];
$yesterdayWeek = date('W',strtotime($yesterday));

//Tomorrow
$tomorrow = strftime("%Y/%m/%d", mktime(0, 0, 0, date('m'), date('d')+1, date('Y'))); 
$tomorrowArray = explode("/", $tomorrow);
$tomorrow_yearNum = $tomorrowArray[0];
$tomorrow_monthNum = $tomorrowArray[1];
$tomorrow_dayNum = $tomorrowArray[2];
$tomorrowWeek = date('W',strtotime($tomorrow));

while($cssExists) {

    $path_mainFile = $directory."main".$i.".css";
    
    //today paths
    $path_cssMonthYear = $directory."main".$i."_m".$monthNum.$yearNum.".css";
    $path_cssWeekYear = $directory."main".$i."_s".$currentWeek.$yearNum.".css";
    $path_cssDayMonthYear = $directory."main".$i."_j".$dayNum.$monthNum.$yearNum.".css";
    
    //yesterday paths
    $path_yesterday_cssMonthYear = $directory."main".$i."_m".$yesterday_monthNum.$yesterday_yearNum.".css";
    $path_yesterday_cssWeekYear = $directory."main".$i."_s".$yesterdayWeek.$yesterday_yearNum.".css";
    $path_yesterday_cssDayMonthYear = $directory."main".$i."_j".$yesterday_dayNum.$yesterday_monthNum.$yesterday_yearNum.".css";

    //tomorrow paths
    $path_tomorrow_cssMonthYear = $directory."main".$i."_m".$tomorrow_monthNum.$tomorrow_yearNum.".css";
    $path_tomorrow_cssWeekYear = $directory."main".$i."_s".$tomorrowWeek.$tomorrow_yearNum.".css";
    $path_tomorrow_cssDayMonthYear = $directory."main".$i."_j".$tomorrow_dayNum.$tomorrow_monthNum.$tomorrow_yearNum.".css";
    
    //we stock everything in an associative array
    $todayPaths = Array( 'today'     => Array (
                                                    'monthYear'    => $path_cssMonthYear,
                                                    'weekYear'     => $path_cssWeekYear,
                                                    'dayMonthYear' => $path_cssDayMonthYear
                                              ),
                         'yesterday' => Array (
                                                    'monthYear'    => $path_yesterday_cssMonthYear,
                                                    'weekYear'     => $path_yesterday_cssWeekYear,
                                                    'dayMonthYear' => $path_yesterday_cssDayMonthYear
                                              ),
                         'tomorrow' => Array  (
                                                    'monthYear'    => $path_tomorrow_cssMonthYear,
                                                    'weekYear'     => $path_tomorrow_cssWeekYear,
                                                    'dayMonthYear' => $path_tomorrow_cssDayMonthYear
                                              )  
                       );
 
    //Does the main<i>.css file exists ?
    if ( file_exists($path_mainFile) ) {
    
        echo "<u>The file <strong>".$path_mainFile."</strong> was found</u><br /><br />";
    
        //check that the files exists for each day (today, yesterday, tomorrow)
        foreach( $todayPaths as $day => $arr ) {

            echo "<b>Generating files for ".$day."</b><br />";
        
            if (! file_exists($todayPaths[$day]['monthYear']) ) {
                echo "<font color='green'>- The file ".$todayPaths[$day]['monthYear']." was successfully created</font><br />";
                $fp = fopen($todayPaths[$day]['monthYear'],"w");
                fclose($fp);  
            }
            else {
                echo "<font color='red'>- The file ".$todayPaths[$day]['monthYear']." was not created because alfready exists</font><br />";
            }

            if (! file_exists($todayPaths[$day]['weekYear']) ) {
                echo "<font color='green'>- The file ".$todayPaths[$day]['weekYear']." was successfully created</font><br />";
                $fp = fopen($todayPaths[$day]['weekYear'],"w");
                fclose($fp);  
            }
            else {
                echo "<font color='red'>- The file ".$todayPaths[$day]['weekYear']." was not created because alfready exists</font><br />";
            }

            if (! file_exists($todayPaths[$day]['dayMonthYear']) ) {
                echo "<font color='green'>- The file ".$todayPaths[$day]['dayMonthYear']." was successfully created</font><br />";
                $fp = fopen($todayPaths[$day]['dayMonthYear'],"w");
                fclose($fp);  
            }
            else {
                echo "<font color='red'>- The file ".$todayPaths[$day]['dayMonthYear']." was not created because alfready exists</font><br />";
            }        
        }
    }
    else {
        //we quit
        $cssExists = false;
    }
    
    echo "<br /><br />";
    
    //first file to chekc is main.css after that it's like main<i>.css (begin at 1)
    if ($i == "") { $i = 1; }
    else          { $i++; }
}

?>